Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- //setup LEDs
- #define NUM_LEDS 8
- #define DATA_PIN 15
- CRGB leds[NUM_LEDS];
- //setup software serial buffer
- char buff[NUM_LEDS*3];
- int buffPos = 0;
- char buffChar;
- void setup ()
- {
- Serial.begin (115200);
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- }
- void loop()
- {
- while (Serial.available() > 0) {
- buffChar = Serial.read();
- if (buffPos < NUM_LEDS*3) {
- buff[buffPos] = buffChar;
- buffPos++;
- if (buffPos == (NUM_LEDS*3)) {
- //clear leds and overwrite with buffer
- memset(leds, 0, sizeof(leds));
- memcpy(leds, buff, sizeof(leds));
- //clear buffer and reset position
- memset(buff, 0, sizeof(buff));
- buffPos = 0;
- }
- }
- }
- //update LEDs
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment