Not
Not
const uint16_t
Num_Leds = 130; // strip length
const uint8_t
Brightness = 255; // maximum brightness
// --------------------------------------------------------------------
#include <FastLED.h>
CRGB leds[Num_Leds];
// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch). You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives. The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.
// Macros initialized
#ifdef SERIAL_FLUSH
#undef SERIAL_FLUSH
#define SERIAL_FLUSH while(Serial.available() > 0) { Serial.read(); }
#else
#define SERIAL_FLUSH
#endif
#ifdef DEBUG_LED
#define D_LED(x) do {digitalWrite(DEBUG_LED, x);} while(0)
#else
#define D_LED(x)
#endif
#ifdef DEBUG_FPS
#define D_FPS do {digitalWrite(DEBUG_FPS, HIGH); digitalWrite(DEBUG_FPS, LOW);}
while (0)
#else
#define D_FPS
#endif
void setup(){
#ifdef DEBUG_LED
pinMode(DEBUG_LED, OUTPUT);
digitalWrite(DEBUG_LED, LOW);
#endif
#ifdef DEBUG_FPS
pinMode(DEBUG_FPS, OUTPUT);
#endif
FastLED.setBrightness(Brightness);
#ifdef CLEAR_ON_START
FastLED.show();
#endif
Serial.begin(SerialSpeed);
Serial.print("Ada\n"); // Send ACK string to host
void loop(){
const int c = Serial.read(); // read one byte
switch(mode) {
case Header:
headerMode(c);
break;
case Data:
dataMode(c);
break;
}
}
else {
// No new data
timeouts();
}
}
FastLED.show();
channelIndex = 0; // reset channel tracking
mode = Header; // begin next header search
D_FPS;
D_LED(LOW);
SERIAL_FLUSH;
}
}
void groupProcessing() {
// if we've received the same amount of data as there
// are LEDs in the strip, don't do any group processing
if (Num_Leds == ledIndex) return;
// otherwise, iterate backwards through the array, copying each LED color
// forwards to the rest of its group
for (uint16_t group = 1; group <= ledIndex; ++group) {
const CRGB GroupColor = leds[ledIndex - group];
const uint16_t GroupStart = Num_Leds - (group * GroupSize);
fill_solid(&leds[GroupStart], GroupSize, GroupColor);
}
}
void timeouts(){
const unsigned long t = now();