hello,
i'm new to Arduino. i'm trying to use three different buttons to change the animations of a led strip.
button 1 to fade in and out specific color
button 2 to change the led strip animation
button 3 to turn it off
but can't seem to figure out to make this work
any help would greatly appreciated
tried to repurpose this sketch to fit my needs
#include <Adafruit_NeoPixel.h>
#define BLUE_BUTTON_PIN 2
#define RED_BUTTON_PIN 3
#define OFF_BUTTON_PIN 4
#define PIXEL_PIN 6
#define PIXEL_COUNT 10
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BLUE_BUTTON_PIN, INPUT_PULLUP);
pinMode(RED_BUTTON_PIN, INPUT_PULLUP);
pinMode(OFF_BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void Red() {
// Get current button state.
bool newState = digitalRead(RED_BUTTON_PIN);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(RED_BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 2)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
//
//void Blue() {
// // Get current button state.
// bool newState = digitalRead(BLUE_BUTTON_PIN);
//
// // Check if state changed from high to low (button press).
// if (newState == LOW && oldState == HIGH) {
// // Short delay to debounce button.
// delay(020);
// // Check if button is still low after debounce.
// newState = digitalRead(BLUE_BUTTON_PIN);
// if (newState == LOW) {
// showType++;
// if (showType > 3)
// showType=0;
// startShow(showType);
// }
// }
//
// // Set the last button state to the old state.
// oldState = newState;
//}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 0); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 0); // Red
break;
case 2: colorWipe(strip.Color(0, 0, 255), 0); // Green
break;
// case 3: colorWipe(strip.Color(0, 0, 255), 0); // Blue
// break;
// case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
// break;
// case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
// break;
// case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue
// break;
// case 7: rainbow(20);
// break;
// case 8: rainbowCycle(20);
// break;
// case 9: theaterChaseRainbow(50);
// break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}