Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop()
- {
- byte data[301];
- Serial.write('a');
- //Add a delay to give sender time to respond to 'a'
- //3 ms is shortest time without glitches**
- delay(3);
- //Now the LED can be read in proper order (R,G,B) unlike before**
- if (Serial.available() > 0){
- Serial.readBytes(data, 301);
- c_interval = data[0];
- for (int i=0; i<100; i++){
- leds[i].r = data[i+1];
- leds[i].g = data[i+101];
- leds[i].b = data[i+201];
- error_mode = 0;
- }
- }
- else{
- error_mode = 1;
- }
- if (error_mode == 0){
- for (int i=0; i<100; i++){
- leds[100+i].r = leds[i].r;
- leds[100+i].g = leds[i].g;
- leds[100+i].b = leds[i].b;
- leds[200+i].r = leds[i].r;
- leds[200+i].g = leds[i].g;
- leds[200+i].b = leds[i].b;
- }
- FastLED.show();
- //Now the c_interval feature works, I approximate delay of above to 24 ms so I subtract 24 from c_interval**
- FastLED.delay(c_interval-24);
- //Empty the serial buffer in case anything left, to avoid reading old data
- while (Serial.available()>0){
- Serial.read();
- }
- }
- else if (error_mode == 1){
- default_pattern();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment