i want it to boot in up in case 0, which it does. then i want the button input to start case 1 then two but i want the button to loop between one and two and then time out to case 0 after five seconds of inactivity from the button. but its not working.
heres the area of code i am trying to acomplish thisin
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
startShow(showType);
showType++;
if (showType > 2)
showType=1;
if (newState == LOW) {
if (millis() - lastPress > 5000);
showType=0;}
}
}
and heres my full scketch
#include <Adafruit_NeoPixel.h>
#include <math.h>
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 12
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 3;
uint32_t lastPress;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(3, OUTPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(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(BUTTON_PIN);
if (newState == LOW) {
startShow(showType);
showType++;
if (showType > 2)
showType=1;
if (newState == LOW) {
if (millis() - lastPress > 5000);
showType=0;}
}
}
// 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;
startShow(showType=0);
break;
case 1: colorWipe(strip.Color(0, 0, 25), 0); // Orange
digitalWrite(3, LOW);
break;
case 2: colorWipe(strip.Color(40, 15, 0), 0); //Blue
digitalWrite(3, LOW);
break;
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(35);
}
}