Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LEDS 60
- CRGB leds[NUM_LEDS];
- #define PIN 2
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- #define FRAMES_PER_SECOND 120
- #define BUTTON_LEAD 4
- //#define BRIGHTNESS_BUTTON 19
- bool buttonState = LOW;
- bool lastButtonState = LOW;
- int mode = 1; //Default mode is one.
- void setup()
- {
- pinMode(BUTTON_LEAD, INPUT_PULLUP);
- FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.show();
- }
- void loop() {
- if(buttonListener()) { line();}
- EVERY_N_MILLISECONDS( 10 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- }
- void line(){
- int LineSize = 4;
- for(int i = 0; i < NUM_LEDS-LineSize-2; i++) {
- FastLED.clear();
- leds[i] += CHSV(gHue, 255, 255);
- for(int j = 1; j <= LineSize; j++) {
- leds[i+j] += CHSV(gHue, 255, 255);
- }
- leds[i+LineSize+1] += CHSV(gHue, 255, 255);
- FastLED.show();
- FastLED.delay(1000/FRAMES_PER_SECOND);
- }
- wipe();
- }
- void wipe(){
- for(int i=0; i<NUM_LEDS; i++){
- leds[i] = CRGB::Black;
- FastLED.show();
- }
- }
- /* monitor button press */
- bool buttonListener() {
- bool modeChanged = false;
- buttonState = digitalRead(BUTTON_LEAD);
- if (buttonState != lastButtonState) {
- if (buttonState == LOW) {
- mode++;
- modeChanged = true;
- delay(250); // Debounce delay. I checked the best parameter and 250 was it.
- }
- }
- lastButtonState = buttonState;
- return modeChanged;
- }
Advertisement
Add Comment
Please, Sign In to add comment