Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastSPI_LED.h>
- //Set the number of leds in the strip.
- #define NUM_LEDS 25
- // Sometimes chipsets wire in a backwards sort of way
- struct CRGB {
- unsigned char b;
- unsigned char r;
- unsigned char g;
- };
- // struct CRGB { unsigned char r; unsigned char g; unsigned char b; };
- struct CRGB *leds;
- // specified under `rate` in the `[device]` section of /etc/boblight.conf
- #define serialRate 38400
- // boblightd sends a prefix (defined in /etc/boblight.conf) before sending the pixel data
- uint8_t prefix[] = {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
- #define PIN 4
- void setup() {
- FastSPI_LED.setLeds(NUM_LEDS);
- //Change this to match your led strip
- FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2811);
- //Change datarate to match your led strip as well
- FastSPI_LED.setDataRate(0);
- //If non-default SPI pins have been used change this.
- FastSPI_LED.setPin(PIN);
- FastSPI_LED.init();
- FastSPI_LED.start();
- leds = (struct CRGB*)FastSPI_LED.getRGBData();
- clearLeds();
- Serial.begin(serialRate);
- }
- void clearLeds(){
- for(int tmpChannel=0; tmpChannel<NUM_LEDS; tmpChannel++){
- leds[tmpChannel].r = 10;
- leds[tmpChannel].b = 0;
- leds[tmpChannel].g = 0;
- };
- FastSPI_LED.show();
- }
- void loop() {
- // wait until we see the prefix
- for(byte i = 0; i < sizeof prefix; ++i) {
- waitLoop: while (!Serial.available()) ;;
- // look for the next byte in the sequence if we see the one we want
- if(prefix[i] == Serial.read()) continue;
- // otherwise, start over
- i = 0;
- goto waitLoop;
- }
- // read the transmitted data
- 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();
- leds[i].r = r;
- leds[i].b = b;
- leds[i].g = g;
- }
- FastSPI_LED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement