ソースを参照

Command one led with button without blinking

DricomDragon 5 年 前
コミット
46862fbb76
1 ファイル変更25 行追加11 行削除
  1. 25 11
      prog/sources/setup-loop.cpp

+ 25 - 11
prog/sources/setup-loop.cpp

@@ -2,6 +2,12 @@
 
 uint32_t antiBlinkBuffer;
 
+const uint32_t bufferEmpty(0);
+const uint32_t bufferFull(~ bufferEmpty);
+
+bool buttonReleased;
+bool actionDone;
+
 DigitalPort LED[5];
 
 void setup (USER_MODE) {
@@ -10,6 +16,10 @@ void setup (USER_MODE) {
 
 	antiBlinkBuffer = 0;
 
+	buttonReleased = digitalRead(P0_PUSH_BUTTON);
+
+	actionDone = false;
+
 	LED[0] = L0_LED;
 	LED[1] = L1_LED;
 	LED[2] = L2_LED;
@@ -18,21 +28,25 @@ void setup (USER_MODE) {
 }
 
 void loop (USER_MODE) {
-	// Wait
-	busyWaitDuring(MODE_ 500);
 
+	// Shift bits
 	antiBlinkBuffer <<= 1;
-	antiBlinkBuffer |= 0x01;
 
-	// Display anti blink buffer
-	uint32_t bitSelector(1);
-	for (uint32_t i(0); i < 5; i++) {
-		digitalWrite(LED[i], antiBlinkBuffer & bitSelector);
-		bitSelector <<= 1;
-	}
+	if (digitalRead(P0_PUSH_BUTTON))
+		antiBlinkBuffer |= 0x01;
 
 	// Command leds with buttons
-	if ( !digitalRead(P0_PUSH_BUTTON) )
-		antiBlinkBuffer = 0;
+	if (antiBlinkBuffer == bufferEmpty) {
+		buttonReleased = false;
+	}
+	else if (antiBlinkBuffer == bufferFull) {
+		buttonReleased = true;
+		actionDone = false;
+	}
+
+	if (!buttonReleased && !actionDone) {
+		digitalToggle(L0_LED);
+		actionDone = true;
+	}
 }