|
@@ -1,52 +1,61 @@
|
|
|
#include "all-headers.h"
|
|
|
|
|
|
-uint32_t antiBlinkBuffer;
|
|
|
-
|
|
|
+// Bit operation references
|
|
|
const uint32_t bufferEmpty(0);
|
|
|
const uint32_t bufferFull(~ bufferEmpty);
|
|
|
|
|
|
-bool buttonReleased;
|
|
|
-bool actionDone;
|
|
|
-
|
|
|
+// Button variables
|
|
|
+uint32_t antiBlinkBuffer[5];
|
|
|
+bool buttonReleased[5];
|
|
|
+bool actionDone[5];
|
|
|
DigitalPort LED[5];
|
|
|
+DigitalPort BUTTON[5];
|
|
|
|
|
|
void setup (USER_MODE) {
|
|
|
// Start
|
|
|
digitalWrite(L0_LED, true);
|
|
|
|
|
|
- antiBlinkBuffer = 0;
|
|
|
-
|
|
|
- buttonReleased = digitalRead(P0_PUSH_BUTTON);
|
|
|
-
|
|
|
- actionDone = false;
|
|
|
+ BUTTON[0] = P0_PUSH_BUTTON;
|
|
|
+ BUTTON[1] = P1_PUSH_BUTTON;
|
|
|
+ BUTTON[2] = P2_PUSH_BUTTON;
|
|
|
+ BUTTON[3] = P3_PUSH_BUTTON;
|
|
|
+ BUTTON[4] = P4_PUSH_BUTTON;
|
|
|
|
|
|
LED[0] = L0_LED;
|
|
|
LED[1] = L1_LED;
|
|
|
LED[2] = L2_LED;
|
|
|
LED[3] = L3_LED;
|
|
|
LED[4] = L4_LED;
|
|
|
+
|
|
|
+ for (unsigned int i(0); i < 5; i++) {
|
|
|
+ antiBlinkBuffer[i] = 0;
|
|
|
+ buttonReleased[i] = digitalRead(BUTTON[i]);
|
|
|
+ actionDone[i] = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void loop (USER_MODE) {
|
|
|
|
|
|
// Shift bits
|
|
|
- antiBlinkBuffer <<= 1;
|
|
|
-
|
|
|
- if (digitalRead(P0_PUSH_BUTTON))
|
|
|
- antiBlinkBuffer |= 0x01;
|
|
|
-
|
|
|
- // Command leds with buttons
|
|
|
- if (antiBlinkBuffer == bufferEmpty) {
|
|
|
- buttonReleased = false;
|
|
|
- }
|
|
|
- else if (antiBlinkBuffer == bufferFull) {
|
|
|
- buttonReleased = true;
|
|
|
- actionDone = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!buttonReleased && !actionDone) {
|
|
|
- digitalToggle(L0_LED);
|
|
|
- actionDone = true;
|
|
|
+ for (unsigned int i(0); i < 5; i++) {
|
|
|
+ antiBlinkBuffer[i] <<= 1;
|
|
|
+
|
|
|
+ if (digitalRead(BUTTON[i]))
|
|
|
+ antiBlinkBuffer[i] |= 0x01;
|
|
|
+
|
|
|
+ // Command leds with buttons
|
|
|
+ if (antiBlinkBuffer[i] == bufferEmpty) {
|
|
|
+ buttonReleased[i] = false;
|
|
|
+ }
|
|
|
+ else if (antiBlinkBuffer[i] == bufferFull) {
|
|
|
+ buttonReleased[i] = true;
|
|
|
+ actionDone[i] = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!buttonReleased[i] && !actionDone[i]) {
|
|
|
+ digitalToggle(LED[i]);
|
|
|
+ actionDone[i] = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|