In a piece off code I am modifying I have a button connected to start the code and then it resets its self afterwards. Is they a way to make the arduino loop that code without manually pressing the button again?
This is a section off the code:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define BUTTON_PIN 9
Adafruit_NeoPixel strip = Adafruit_NeoPixel(120, PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
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) {
showType++;
if (showType > 9)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
colorWipe(strip.Color(75, 0, 0), 50); // Red
colorWipe(strip.Color(0, 75, 0), 50); // Green
colorWipe(strip.Color(0, 0, 75), 50); // Blue
theaterChase(strip.Color(75, 75, 75), 50); // White
theaterChase(strip.Color(75, 0, 0), 50); // Red
theaterChase(strip.Color(0, 0, 75), 50); // Blue
rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
resetFunc(); //call reset
}
Thanks Reece
loop()
function, and renamevoid startShow(int i)
asvoid loop()
.startShow(showType);
to just above ` oldState = newState;`. That way it get called al the time, and the button still changes the showType.