Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Button.h>
- #include <FastLED.h>
- #define LED_PIN 11
- #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.
- #define BUTTON_PIN 10
- Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
- boolean ledState; //A variable that keeps the current LED status
- CRGB leds[NUM_LEDS];
- int showType = 0;
- const uint8_t maxEffects = 6;
- /*void rainbow2(uint8_t wait) {
- static byte hue = 0;
- for(hue=0; hue < 256; hue++) {
- fill_rainbow( &(leds[0]), NUM_LEDS, hue);
- myBtn.read();
- LEDS.show();
- LEDS.delay(wait);
- myBtn.read();
- if (myBtn.isPressed()) { //If the button was pressed, change the LED state
- showType++;
- if (showType >6) {showType=0;}
- startShow(showType);
- }
- }
- }
- */
- volatile uint8_t hue = 0;
- static void effectOne(){
- FastLED.clear();
- fill_rainbow( &(leds[0]), NUM_LEDS, hue);
- hue++;
- FastLED.show();
- }
- void setup()
- {
- delay( 3000 ); // power-up safety delay
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- }
- int lastState = 0;
- int currentState = 0;
- int p = 0;
- void loop()
- {
- 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:
- effectOne();
- break;
- case 5:
- leds[0] = CRGB::Gray;
- leds[1] = CRGB::Gray;
- leds[2] = CRGB::Gray;
- FastLED.show();
- break;
- case 6: leds[0] = CRGB::Linen;
- leds[1] = CRGB::Moccasin;
- leds[2] = CRGB::Linen;
- FastLED.show();
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment