#include"FastLED.h"// How many leds in your strip?#define NUM_LEDS 16// For led chips like Neopixels, which have a data line, ground, and power, you just// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN#define DATA_PIN 17// Define the array of ledsCRGBleds[NUM_LEDS];CHSVcurrent_color;// Temporary HSV variable to make it easy to change colors#define GREEN_TIME 576#define RED_TIME 38voidsetup(){uint8_ti;FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);// Set all LEDs to initial color (Green)for(i=0;i<NUM_LEDS;i++){leds[i]=CRGB::Green;}FastLED.show();current_color=CHSV(96,255,255);Serial.begin(9600);Serial.print("Start\n");}voidloop(){uint8_ti;staticint8_tincrement=-1;staticuint8_tstate=0;staticuint32_tstate_timer=0;// state 0: Hold on to green for some time// go into state 1 when time is upif(state==0){state_timer+=1;if(state_timer==GREEN_TIME){state_timer=0;state=1;Serial.print("Finished green time\n");}}// state 1: roll down to red// go into state 2 when redelseif(state==1){current_color.hue-=1;if(current_color.hue==0){state=2;Serial.print("Reached red, going back to green\n");}}// state 2: wait at red// go into state 3 when done waitingelseif(state==2){state_timer+=1;if(state_timer==RED_TIME){state_timer=0;state=3;Serial.print("Finished red time\n");}}// state 3: roll up to green// go into state 0 when greenelseif(state==3){current_color.hue+=1;if(current_color.hue==96){state=0;Serial.print("Reached green, waiting\n");}}// Show LEDshsv2rgb_rainbow(current_color,leds[0]);for(i=1;i<NUM_LEDS;i++){leds[i]=leds[0];}FastLED.show();delay(1562);}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.