123456789101112131415161718192021222324252627282930313233 |
- //Update Shift Register to flush new bits into signal LEDs
- void updateShiftRegister() {
- // Prepare the data to be shifted into the shift register
- byte data = 0b00000000; // Clear the bits
- for (int i=0; i < numButtons; i++){
- data |= buttonStates[i] << (7 - i);
- }
- //Handling signal LED blinks
- if (blueLED){
- data |= 0b1 << 0;
- }
- if (yellowLED){
- data |= 0b1 << 1;
- }
- if (redLED){
- data |= 0b1 << 2;
- }
- // Shift the data into the shift register
- for (int i = 7; i >= 0; --i) {
- digitalWrite(SER_PIN, (data >> i) & 0b1);
- digitalWrite(SRCLK_PIN, HIGH);
- delay(1); // Optional: Adjust delay if needed
- digitalWrite(SRCLK_PIN, LOW);
- }
- // Latch the data to the output pins of the shift register
- digitalWrite(RCLK_PIN, HIGH);
- delay(1); // Optional: Adjust delay if needed
- digitalWrite(RCLK_PIN, LOW);
- }
|