Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #include <bitswap.h>
  2. #include <chipsets.h>
  3. #include <color.h>
  4. #include <colorpalettes.h>
  5. #include <colorutils.h>
  6. #include <controller.h>
  7. #include <cpp_compat.h>
  8. #include <dmx.h>
  9. #include <FastLED.h>
  10. #include <fastled_config.h>
  11. #include <fastled_delay.h>
  12. #include <fastled_progmem.h>
  13. #include <fastpin.h>
  14. #include <fastspi.h>
  15. #include <fastspi_bitbang.h>
  16. #include <fastspi_dma.h>
  17. #include <fastspi_nop.h>
  18. #include <fastspi_ref.h>
  19. #include <fastspi_types.h>
  20. #include <hsv2rgb.h>
  21. #include <led_sysdefs.h>
  22. #include <lib8tion.h>
  23. #include <noise.h>
  24. #include <pixelset.h>
  25. #include <pixeltypes.h>
  26. #include <platforms.h>
  27. #include <power_mgt.h>
  28. #include "FastLED.h"
  29.  
  30. // How many leds in your strip?
  31. #define NUM_LEDS 114
  32.  
  33. // For led chips like Neopixels, which have a data line, ground, and power, you just
  34. // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
  35. // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
  36. #define DATA_PIN 6
  37.  
  38. #define COLOR_ORDER RGB
  39.  
  40. // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
  41. uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
  42.  
  43. // Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
  44. #define serialRate 460800
  45.  
  46. // Define the array of leds
  47. CRGB leds[NUM_LEDS];
  48.  
  49. void setup() {
  50. // Uncomment/edit one of the following lines for your leds arrangement.
  51. // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
  52. // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
  53. // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
  54. // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  55. // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  56. FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  57. // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  58. // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  59. // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
  60. // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
  61. // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  62.  
  63. // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
  64. // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
  65. // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
  66.  
  67. // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  68. // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  69. // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  70.  
  71. // initial RGB flash
  72. LEDS.showColor(CRGB(255, 0, 0));
  73. delay(500);
  74. LEDS.showColor(CRGB(0, 255, 0));
  75. delay(500);
  76. LEDS.showColor(CRGB(0, 0, 255));
  77. delay(500);
  78. LEDS.showColor(CRGB(0, 0, 0));
  79.  
  80. Serial.begin(serialRate);
  81. Serial.print("Ada\n"); // Send "Magic Word" string to host
  82.  
  83. }
  84.  
  85. void loop() {
  86. // wait for first byte of Magic Word
  87. for(i = 0; i < sizeof prefix; ++i) {
  88. waitLoop: while (!Serial.available()) ;;
  89. // Check next byte in Magic Word
  90. if(prefix[i] == Serial.read()) continue;
  91. // otherwise, start over
  92. i = 0;
  93. goto waitLoop;
  94. }
  95.  
  96. // Hi, Lo, Checksum
  97.  
  98. while (!Serial.available()) ;;
  99. hi=Serial.read();
  100. while (!Serial.available()) ;;
  101. lo=Serial.read();
  102. while (!Serial.available()) ;;
  103. chk=Serial.read();
  104.  
  105. // if checksum does not match go back to wait
  106. if (chk != (hi ^ lo ^ 0x55))
  107. {
  108. i=0;
  109. goto waitLoop;
  110. }
  111.  
  112. memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  113. // read the transmission data and set LED values
  114. for (uint8_t i = 0; i < NUM_LEDS; i++) {
  115. byte r, g, b;
  116. while(!Serial.available());
  117. r = Serial.read();
  118. while(!Serial.available());
  119. g = Serial.read();
  120. while(!Serial.available());
  121. b = Serial.read();
  122. leds[i].r = r;
  123. leds[i].g = g;
  124. leds[i].b = b;
  125. }
  126. // shows new values
  127. FastLED.show();
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement