Guest User

Untitled

a guest
May 22nd, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. void loop()
  2. {
  3. byte data[301];
  4. Serial.write('a');
  5.  
  6. //Add a delay to give sender time to respond to 'a'
  7. //3 ms is shortest time without glitches**
  8. delay(3);
  9.  
  10. //Now the LED can be read in proper order (R,G,B) unlike before**
  11.  
  12. if (Serial.available() > 0){
  13. Serial.readBytes(data, 301);
  14. c_interval = data[0];
  15. for (int i=0; i<100; i++){
  16. leds[i].r = data[i+1];
  17. leds[i].g = data[i+101];
  18. leds[i].b = data[i+201];
  19. error_mode = 0;
  20. }
  21. }
  22. else{
  23. error_mode = 1;
  24. }
  25. if (error_mode == 0){
  26. for (int i=0; i<100; i++){
  27. leds[100+i].r = leds[i].r;
  28. leds[100+i].g = leds[i].g;
  29. leds[100+i].b = leds[i].b;
  30. leds[200+i].r = leds[i].r;
  31. leds[200+i].g = leds[i].g;
  32. leds[200+i].b = leds[i].b;
  33. }
  34. FastLED.show();
  35.  
  36. //Now the c_interval feature works, I approximate delay of above to 24 ms so I subtract 24 from c_interval**
  37. FastLED.delay(c_interval-24);
  38.  
  39. //Empty the serial buffer in case anything left, to avoid reading old data
  40. while (Serial.available()>0){
  41. Serial.read();
  42. }
  43. }
  44. else if (error_mode == 1){
  45. default_pattern();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment