Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2.  
  3. #define FORCE_SOFTWARE_SPI
  4. //#define FORCE_SOFTWARE_PINS
  5. #include "FastLED.h"
  6. #define NUM_LEDS 30
  7. #define PIN 4
  8. #define serialRate 115200
  9.  
  10. // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
  11. uint8_t prefix[] = {
  12. 'A', 'd', 'a'}
  13. , hi, lo, chk, i;
  14. int temp;
  15. // initialise LED-array
  16. CRGB diody[NUM_LEDS];
  17.  
  18. void setup()
  19. {
  20. FastLED.addLeds<WS2812B, PIN, GRB>(diody, NUM_LEDS);
  21. // FastLED.addLeds<WS2812B, PIN, BGR>(diody, NUM_LEDS);
  22. // initial RGB flash
  23. LEDS.showColor(CRGB(255, 0, 0));
  24. delay(1000);
  25. LEDS.showColor(CRGB(0, 255, 0));
  26. delay(1000);
  27. LEDS.showColor(CRGB(0, 0, 255));
  28. delay(1000);
  29. LEDS.showColor(CRGB(0, 0, 0));
  30.  
  31. Serial.begin(serialRate);
  32. Serial.print("Ada\n"); // Send "Magic Word" string to host
  33.  
  34. }
  35.  
  36. void loop() {
  37.  
  38. LEDS.showColor(CRGB(0, 0, 0));
  39. // wait for first byte of Magic Word
  40. for(i = 0; i < sizeof prefix; ++i) {
  41. waitLoop:
  42. while (!Serial.available()) ;
  43. ;
  44. // Check next byte in Magic Word
  45. if(prefix[i] == Serial.read()) continue;
  46. // otherwise, start over
  47. i = 0;
  48. goto waitLoop;
  49. }
  50.  
  51. // Hi, Lo, Checksum
  52.  
  53. while (!Serial.available()) ;
  54. ;
  55. hi=Serial.read();
  56. while (!Serial.available()) ;
  57. ;
  58. lo=Serial.read();
  59. while (!Serial.available()) ;
  60. ;
  61. chk=Serial.read();
  62.  
  63. // if checksum does not match go back to wait
  64. if (chk != (hi ^ lo ^ 0x55))
  65. {
  66. i=0;
  67. goto waitLoop;
  68. }
  69.  
  70. memset(diody, 0, NUM_LEDS * sizeof(struct CRGB));
  71. // read the transmission data and set LED values
  72. for (uint8_t i = 0; i < NUM_LEDS; i++) {
  73. byte r, g, b;
  74.  
  75. while(!Serial.available());
  76. r = Serial.read();
  77. while(!Serial.available());
  78. g = Serial.read();
  79. while(!Serial.available());
  80. b = Serial.read();
  81. diody[i].r = r;
  82. diody[i].g = g;
  83. diody[i].b = b;
  84. if (i==NUM_LEDS)
  85. {
  86. i=1;
  87. delay(1000);
  88. }
  89.  
  90. if (temp==1) {
  91. FastLED.show();
  92. temp=0;
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement