Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Button.h>
- #include <FastLED.h>
- #define LED_PIN 11
- #define BUTTON_PIN 10
- #define NUM_LEDS 3
- #define BRIGHTNESS 128
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define UPDATES_PER_SECOND 100
- #define PULLUP true //To keep things simple, we use the Arduino's internal pullup resistor.
- #define INVERT true //Since the pullup resistor will keep the pin high unless the
- //switch is closed, this is negative logic, i.e. a high state
- //means the button is NOT pressed. (Assuming a normally open switch.)
- #define DEBOUNCE_MS 20 //A debounce time of 20 milliseconds usually works well for tactile button switches.
- Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
- CRGB leds[NUM_LEDS];
- int showType = 0;
- long pause = 20;
- unsigned long previousMillis = 0;
- unsigned long currentMillis = millis();
- uint8_t bow = 0;
- uint8_t hueTick = 0;
- /* --------------EFFECTS---------------------------*/
- void rainbow(int interval){
- fill_rainbow( &(leds[0]), NUM_LEDS, hueTick);
- LEDS.show();
- LEDS.delay(interval);
- if (hueTick >255) {hueTick = 0;}
- }
- /* --------------EFFECTS---------------------------*/
- void setup()
- {
- Serial.begin(9600);
- delay( 3000 ); // power-up safety delay
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- }
- void loop()
- {
- hueTick++;
- myBtn.read(); //Read the button
- if (myBtn.wasPressed()) { //If the button was released, change the LED state
- showType++;
- if (showType >6) {showType=0;}}
- startShow(showType);
- }
- void startShow(int i) {
- switch(i){
- case 0: leds[0] = CRGB::Red;
- leds[1] = CRGB::Aqua;
- leds[2] = CRGB::Aqua;
- FastLED.show();
- break;
- case 1: leds[0] = CRGB::LimeGreen;
- leds[1] = CRGB::LimeGreen;
- leds[2] = CRGB::LimeGreen;
- FastLED.show();
- break;
- case 2: leds[0] = CRGB::Purple;
- leds[1] = CRGB::Purple;
- leds[2] = CRGB::Purple;
- FastLED.show();
- break;
- case 3: leds[0] = CRGB::DarkSlateBlue;
- leds[1] = CRGB::DarkSlateBlue;
- leds[2] = CRGB::DarkSlateBlue;
- FastLED.show();
- break;
- case 4:
- rainbow(10);
- break;
- case 5:
- leds[0] = CRGB::Gray;
- leds[1] = CRGB::Gray;
- leds[2] = CRGB::Gray;
- FastLED.show();
- break;
- case 6: rainbow(40);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment