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;
- unsigned long previousBlueMillis = 0;
- const long blueInterval = 35;
- unsigned long previousGoldMillis = 0;
- const long goldInterval = 35;
- 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(){
- int b = 0;
- unsigned long currentBlueMillis = millis();
- if (currentBlueMillis - previousBlueMillis >= blueInterval) {
- previousBlueMillis = currentBlueMillis;
- b++;
- leds[b]=CRGB::Blue;
- FastLED.show();}
- }
- void goldChase(){
- int g = 0;
- unsigned long currentGoldMillis = millis();
- if (currentGoldMillis - previousGoldMillis >= goldInterval) {
- previousGoldMillis = currentGoldMillis;
- g++;
- leds[g]=CRGB::Gold;
- FastLED.show();}
- }
- 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