File tree Expand file tree Collapse file tree 1 file changed +20
-17
lines changed
examples/ProductionSketch Expand file tree Collapse file tree 1 file changed +20
-17
lines changed Original file line number Diff line number Diff line change 44#include < Arduino.h>
55
66void serialLoop (CRGB* leds) {
7+
78 static int pixelIndex;
89 int idx = 0 ;
910 uint8_t buffer[3 ];
11+ uint8_t c;
12+
1013 while (true ) {
11- if (Serial.available ()) {
12- uint8_t c = Serial.read ();
14+ if (Serial.available () > 0 ) {
15+ c = Serial.read ();
1316 if (c == 255 ) {
14- LEDS.show ();
15- pixelIndex = 0 ;
16- idx = 0 ;
17- // BUTTON_IN (D10): 07 - 0111
18- // EXTRA_PIN_A(D7): 11 - 1011
19- // EXTRA_PIN_B (D11): 13 - 1101
20- // ANALOG_INPUT (A9): 14 - 1110
21-
22- char c = (digitalRead (BUTTON_IN) << 3 )
23- | (digitalRead (EXTRA_PIN_A) << 2 )
24- | (digitalRead (EXTRA_PIN_B) << 1 )
25- | (digitalRead (ANALOG_INPUT) );
26- Serial.write (c);
17+ LEDS.show ();
18+ pixelIndex = 0 ;
19+ idx = 0 ;
20+ // BUTTON_IN (D10): 07 - 0111
21+ // EXTRA_PIN_A(D7): 11 - 1011
22+ // EXTRA_PIN_B (D11): 13 - 1101
23+ // ANALOG_INPUT (A9): 14 - 1110
24+
25+ char c = (digitalRead (BUTTON_IN) << 3 )
26+ | (digitalRead (EXTRA_PIN_A) << 2 )
27+ | (digitalRead (EXTRA_PIN_B) << 1 )
28+ | (digitalRead (ANALOG_INPUT) );
29+ Serial.write (c);
2730 } else {
28- buffer[idx++] = Serial. read () ;
31+ buffer[idx++] = c ;
2932 if (idx == 3 ) {
3033 if (pixelIndex == LED_COUNT) break ; // Prevent overflow by ignoring the pixel data beyond LED_COUNT
3134 leds[pixelIndex] = CRGB (buffer[0 ], buffer[1 ], buffer[2 ]);
@@ -35,4 +38,4 @@ void serialLoop(CRGB* leds) {
3538 }
3639 }
3740 }
38- }
41+ }
You can’t perform that action at this time.
0 commit comments