Guest User

Untitled

a guest
Feb 6th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define NUM_LEDS 1024
  4. #define DATA_PIN 7
  5.  
  6. CRGB leds[NUM_LEDS];
  7.  
  8. int colors[8][3]={
  9. {255,0,0},
  10. {0,255,0},
  11. {0,0,255},
  12. {255,255,0},
  13. {0,255,255},
  14. {255,0,255},
  15. {255,255,255},
  16. {0,0,0}
  17. };
  18.  
  19. void setup() {
  20. FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  21. Serial.begin(1000000);
  22. bootupColorSequence();
  23. }
  24.  
  25. void bootupColorSequence(){
  26. for(int i=0;i<8;i++){
  27. fill(colors[i][0],colors[i][1],colors[i][2]);
  28. FastLED.show();
  29. delay(100);
  30. }
  31. }
  32.  
  33.  
  34. int serialReadBlocking(){
  35. while(!Serial.available()){}
  36. return Serial.read();
  37. }
  38. //result code:
  39. //0 = everything fine.
  40. //1 = no data, read timed out
  41. //2 = frame incomplete
  42. //3 = bad header
  43. int numRead = 0;
  44. int readFromSerial2(){
  45. int result = 0;
  46. if(numRead!=NUM_LEDS*3)
  47. Serial.write((byte)1);
  48. else
  49. Serial.write((byte)0);
  50. Serial.flush();
  51. numRead = Serial.readBytes((char*)leds, NUM_LEDS*3);
  52. return result;
  53. }
  54.  
  55. void fill(int r,int g, int b){
  56. for(long i=0;i<NUM_LEDS;i++)
  57. {
  58. leds[i].r = r;
  59. leds[i].g = g;
  60. leds[i].b = b;
  61. }
  62. }
  63.  
  64. void loop() {
  65. int status = readFromSerial2();
  66. FastLED.show();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment