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;
- void rainbow(uint8_t wait) {
- uint16_t hue;
- FastLED.clear();
- for(hue=10; hue<255*3; hue++) {
- myBtn.read();
- if (myBtn.wasPressed()) { //If the button was pressed, change the LED state
- showType++;
- if (showType >5) {
- showType=0;
- startShow(showType);
- }
- }
- else {
- fill_rainbow( &(leds[0]), NUM_LEDS /*led count*/, hue /*starting hue*/);
- FastLED.show();
- LEDS.delay(wait);
- }
- }
- }
- 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 >5) 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(30);
- break;
- case 5: rainbow(40);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment