Guest User

WS2811 Adalight Ambibox Arduino

a guest
Mar 29th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include "FastLED.h"
  2. #define NUM_LEDS 50
  3. #define DATA_PIN 6
  4. #define serialRate 500000
  5. static const uint8_t prefix[] = {'A', 'd', 'a'};
  6.  
  7. // Define the array of leds
  8. CRGB leds[NUM_LEDS];
  9.  
  10. void setup() {
  11. FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  12. Serial.begin(serialRate);
  13. Serial.print("Ada\n");
  14. }
  15.  
  16. void loop() {
  17. for(int i = 0; i < sizeof(prefix); ++i){
  18. while (!Serial.available());
  19. if(prefix[i] != Serial.read())
  20. return;
  21. }
  22. while(Serial.available() < 3);
  23. int highByte = Serial.read();
  24. int lowByte = Serial.read();
  25. int checksum = Serial.read();
  26. if (checksum != (highByte ^ lowByte ^ 0x55)){
  27. return;}
  28.  
  29. uint16_t ledCount = ((highByte & 0x00FF) << 8 | (lowByte & 0x00FF) ) + 1;
  30. if (ledCount > NUM_LEDS){
  31. ledCount = NUM_LEDS;}
  32.  
  33. for (int i = 0; i < ledCount; i++){
  34. while(Serial.available() < 3);
  35. leds[i].r = Serial.read();
  36. leds[i].g = Serial.read();
  37. leds[i].b = Serial.read();}
  38. FastLED.show();
  39. }
Add Comment
Please, Sign In to add comment