setup-loop.cpp 848 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "all-headers.h"
  2. uint32_t antiBlinkBuffer;
  3. const uint32_t bufferEmpty(0);
  4. const uint32_t bufferFull(~ bufferEmpty);
  5. bool buttonReleased;
  6. bool actionDone;
  7. DigitalPort LED[5];
  8. void setup (USER_MODE) {
  9. // Start
  10. digitalWrite(L0_LED, true);
  11. antiBlinkBuffer = 0;
  12. buttonReleased = digitalRead(P0_PUSH_BUTTON);
  13. actionDone = false;
  14. LED[0] = L0_LED;
  15. LED[1] = L1_LED;
  16. LED[2] = L2_LED;
  17. LED[3] = L3_LED;
  18. LED[4] = L4_LED;
  19. }
  20. void loop (USER_MODE) {
  21. // Shift bits
  22. antiBlinkBuffer <<= 1;
  23. if (digitalRead(P0_PUSH_BUTTON))
  24. antiBlinkBuffer |= 0x01;
  25. // Command leds with buttons
  26. if (antiBlinkBuffer == bufferEmpty) {
  27. buttonReleased = false;
  28. }
  29. else if (antiBlinkBuffer == bufferFull) {
  30. buttonReleased = true;
  31. actionDone = false;
  32. }
  33. if (!buttonReleased && !actionDone) {
  34. digitalToggle(L0_LED);
  35. actionDone = true;
  36. }
  37. }