Quellcode durchsuchen

Experiment with bit operators

DricomDragon vor 5 Jahren
Ursprung
Commit
4d4b525601
1 geänderte Dateien mit 27 neuen und 2 gelöschten Zeilen
  1. 27 2
      prog/sources/setup-loop.cpp

+ 27 - 2
prog/sources/setup-loop.cpp

@@ -1,13 +1,38 @@
 #include "all-headers.h"
 
+uint32_t antiBlinkBuffer;
+
+DigitalPort LED[5];
+
 void setup (USER_MODE) {
 	// Start
 	digitalWrite(L0_LED, true);
+
+	antiBlinkBuffer = 0;
+
+	LED[0] = L0_LED;
+	LED[1] = L1_LED;
+	LED[2] = L2_LED;
+	LED[3] = L3_LED;
+	LED[4] = L4_LED;
 }
 
 void loop (USER_MODE) {
+	// Wait
+	busyWaitDuring(MODE_ 500);
+
+	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;
+	}
+
 	// Command leds with buttons
-	if ( digitalRead(P0_PUSH_BUTTON) )
-		digitalToggle(L0_LED);
+	if ( !digitalRead(P0_PUSH_BUTTON) )
+		antiBlinkBuffer = 0;
 }