File tree Expand file tree Collapse file tree 1 file changed +21
-29
lines changed
Expand file tree Collapse file tree 1 file changed +21
-29
lines changed Original file line number Diff line number Diff line change 11#include < FastLED.h>
2- #include < avr/pgmspace.h>
2+ // #include <avr/pgmspace.h>
33#include < Animation.h>
4+
45#include " animation.h"
56
67#define LED_COUNT 60
@@ -33,42 +34,33 @@ void setup()
3334
3435
3536void serialLoop () {
37+
3638 static int pixelIndex;
39+ uint8_t idx = 0 ;
40+ uint8_t buffer[3 ];
41+ uint8_t c;
3742
38- unsigned long lastReceiveTime = millis ();
39-
4043 while (true ) {
41-
42- if (Serial.available () > 2 ) {
43- lastReceiveTime = millis ();
44-
45- uint8_t buffer[3 ]; // Buffer to store three incoming bytes used to compile a single LED color
46-
47- for (uint8_t x=0 ; x<3 ; x++) { // Read three incoming bytes
48- uint8_t c = Serial.read ();
49-
50- if (c < 255 ) {
51- buffer[x] = c; // Using 255 as a latch semaphore
52- }
53- else {
54- LEDS.show ();
55- pixelIndex = 0 ;
56- break ;
57- }
58-
59- if (x == 2 ) { // If we received three serial bytes
60- if (pixelIndex == LED_COUNT) break ; // Prevent overflow by ignoring the pixel data beyond LED_COUNT
44+ if (Serial.available () > 0 ) {
45+ c = Serial.read ();
46+ if (c == 255 ) {
47+ LEDS.show ();
48+ pixelIndex = 0 ;
49+ idx = 0 ;
50+ // BUTTON_IN (D10): 07 - 0111
51+ // EXTRA_PIN_A(D7): 11 - 1011
52+ // EXTRA_PIN_B (D11): 13 - 1101
53+ // ANALOG_INPUT (A9): 14 - 1110
54+ } else {
55+ buffer[idx++] = c;
56+ if (idx == 3 ) {
57+ if (pixelIndex == MAX_LEDS) break ; // Prevent overflow by ignoring the pixel data beyond LED_COUNT
6158 leds[pixelIndex] = CRGB (buffer[0 ], buffer[1 ], buffer[2 ]);
6259 pixelIndex++;
60+ idx = 0 ;
6361 }
6462 }
6563 }
66-
67- // If we haven't received data in 4 seconds, return to playing back our animation
68- if (millis () > lastReceiveTime + 4000 ) {
69- // TODO: Somehow the serial port gets trashed here, how to reset it?
70- return ;
71- }
7264 }
7365}
7466
You can’t perform that action at this time.
0 commit comments