Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LEDS 1024
- #define DATA_PIN 7
- CRGB leds[NUM_LEDS];
- int colors[8][3]={
- {255,0,0},
- {0,255,0},
- {0,0,255},
- {255,255,0},
- {0,255,255},
- {255,0,255},
- {255,255,255},
- {0,0,0}
- };
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
- Serial.begin(1000000);
- bootupColorSequence();
- }
- void bootupColorSequence(){
- for(int i=0;i<8;i++){
- fill(colors[i][0],colors[i][1],colors[i][2]);
- FastLED.show();
- delay(100);
- }
- }
- int serialReadBlocking(){
- while(!Serial.available()){}
- return Serial.read();
- }
- //result code:
- //0 = everything fine.
- //1 = no data, read timed out
- //2 = frame incomplete
- //3 = bad header
- int numRead = 0;
- int readFromSerial2(){
- int result = 0;
- if(numRead!=NUM_LEDS*3)
- Serial.write((byte)1);
- else
- Serial.write((byte)0);
- Serial.flush();
- numRead = Serial.readBytes((char*)leds, NUM_LEDS*3);
- return result;
- }
- void fill(int r,int g, int b){
- for(long i=0;i<NUM_LEDS;i++)
- {
- leds[i].r = r;
- leds[i].g = g;
- leds[i].b = b;
- }
- }
- void loop() {
- int status = readFromSerial2();
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment