leds.ino 891 B

123456789101112131415161718192021222324252627282930313233
  1. //Update Shift Register to flush new bits into signal LEDs
  2. void updateShiftRegister() {
  3. // Prepare the data to be shifted into the shift register
  4. byte data = 0b00000000; // Clear the bits
  5. for (int i=0; i < numButtons; i++){
  6. data |= buttonStates[i] << (7 - i);
  7. }
  8. //Handling signal LED blinks
  9. if (blueLED){
  10. data |= 0b1 << 0;
  11. }
  12. if (yellowLED){
  13. data |= 0b1 << 1;
  14. }
  15. if (redLED){
  16. data |= 0b1 << 2;
  17. }
  18. // Shift the data into the shift register
  19. for (int i = 7; i >= 0; --i) {
  20. digitalWrite(SER_PIN, (data >> i) & 0b1);
  21. digitalWrite(SRCLK_PIN, HIGH);
  22. delay(1); // Optional: Adjust delay if needed
  23. digitalWrite(SRCLK_PIN, LOW);
  24. }
  25. // Latch the data to the output pins of the shift register
  26. digitalWrite(RCLK_PIN, HIGH);
  27. delay(1); // Optional: Adjust delay if needed
  28. digitalWrite(RCLK_PIN, LOW);
  29. }