Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LEDS 64
- #define PIN 2
- #define BUTTON_PIN 4
- CRGB leds [NUM_LEDS];
- uint8_t gHue = 0; //rotating "base" color
- bool buttonState = LOW;
- bool lastButtonState = LOW;
- void setup(){
- pinMode(BUTTON_LEAD,INPUT_PULLUP);
- FastLED.addLeds<WS2812B,PIN,GRB,>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(64);
- }
- void loop(){
- if (buttonListener()){line();}
- }
- void fadeall(){for(int i=0; i<NUM_LEDS;i++){leds[i].nscale8(150);}}
- void line(){
- for(int i=0; i<NUM_LEDS+8; i++){
- if(buttonListener()) {i=0;}
- leds[i] = CHSV (gHue++,255,255);
- FastLED.show();
- fadeall();
- delay(3);
- }
- }
- bool buttonListener(){ //monitor button press
- bool modeChanged = false;
- buttonState = digitalRead(BUTTON_PIN);
- if(buttonState != lastButtonState{ if (buttonState == LOW){
- mode++ //probably not needed here
- modeChanged = true;
- delay(150); //debouncing delay
- }
- }
- lastButtonState = buttonState;
- return modeChanged;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement