Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneButton.h>
- #include <FastLED.h>
- #define NUM_LEDS 44
- #define DATA_PIN 6
- CRGB leds[NUM_LEDS];
- unsigned long previousPixMillis = 0;
- const long pixInterval = 4000;
- int pixel = LOW;
- //button definitions
- #define BUTTON_PIN 8
- OneButton button(BUTTON_PIN, true);
- int currentAction = 1;
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PIN, RBG>(leds, NUM_LEDS);
- FastLED.setCorrection(TypicalPixelString);
- button.attachClick(singleClick);
- }
- void loop() {
- button.tick();
- if (currentAction == 1){
- pixelSwitch();
- }
- }
- void pixelSwitch(){
- unsigned long currentPixMillis = millis();
- if (currentPixMillis - previousPixMillis >= pixInterval) {
- previousPixMillis = currentPixMillis;
- if (pixel == LOW){
- blueChase();
- pixel = HIGH;
- }
- else if (pixel == HIGH){
- goldChase();
- pixel = LOW;
- }
- }
- }
- void blueChase(){
- for (int i=0; i<NUM_LEDS; i++){
- leds[i]=CRGB::Blue;
- FastLED.show();
- delay(35);
- }
- }
- void goldChase(){
- for (int i=0; i<NUM_LEDS; i++){
- leds[i]=CRGB::Gold;
- FastLED.show();
- delay(35);
- }
- }
- void singleClick() {
- if (currentAction == 1){
- currentAction = 2;
- fill_solid(leds, NUM_LEDS, CRGB::Gold);
- FastLED.show();
- }
- else if (currentAction == 2){
- currentAction = 3;
- fill_solid(leds, NUM_LEDS, CRGB::Blue);
- FastLED.show();
- }
- else if (currentAction == 3){
- currentAction = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment