Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FORCE_SOFTWARE_SPI
- //#define FORCE_SOFTWARE_PINS
- #include "FastLED.h"
- #define NUM_LEDS 30
- #define PIN 4
- #define serialRate 115200
- // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
- uint8_t prefix[] = {
- 'A', 'd', 'a'}
- , hi, lo, chk, i;
- // initialise LED-array
- CRGB diody[NUM_LEDS];
- void setup()
- {
- FastLED.addLeds<WS2812B, PIN, GRB>(diody, NUM_LEDS);
- // FastLED.addLeds<WS2812B, PIN, BGR>(diody, NUM_LEDS);
- // initial RGB flash
- LEDS.showColor(CRGB(255, 0, 0));
- delay(1000);
- LEDS.showColor(CRGB(0, 255, 0));
- delay(1000);
- LEDS.showColor(CRGB(0, 0, 255));
- delay(1000);
- LEDS.showColor(CRGB(0, 0, 0));
- Serial.begin(serialRate);
- Serial.print("Ada\n"); // Send "Magic Word" string to host
- }
- void loop() {
- LEDS.showColor(CRGB(0, 0, 0));
- // wait for first byte of Magic Word
- for(i = 0; i < sizeof prefix; ++i) {
- waitLoop:
- while (!Serial.available()) ;
- ;
- // Check next byte in Magic Word
- if(prefix[i] == Serial.read()) continue;
- // otherwise, start over
- i = 0;
- goto waitLoop;
- }
- // Hi, Lo, Checksum
- while (!Serial.available()) ;
- ;
- hi=Serial.read();
- while (!Serial.available()) ;
- ;
- lo=Serial.read();
- while (!Serial.available()) ;
- ;
- chk=Serial.read();
- // if checksum does not match go back to wait
- if (chk != (hi ^ lo ^ 0x55))
- {
- i=0;
- goto waitLoop;
- }
- memset(diody, 0, NUM_LEDS * sizeof(struct CRGB));
- // read the transmission data and set LED values
- for (uint8_t i = 0; i < NUM_LEDS; i++) {
- byte r, g, b;
- while(!Serial.available());
- r = Serial.read();
- while(!Serial.available());
- g = Serial.read();
- while(!Serial.available());
- b = Serial.read();
- diody[i].r = r;
- diody[i].g = g;
- diody[i].b = b;
- }
- // shows new values
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement