int modeButton = 2; // is this unused on your Arduino?
int buttonMode;
int lastButtonMode;
int tristate = 0; // get more for less out of one button
int led = LED_BUILTIN;
void setup() {
Serial.begin(9600);
pinMode(modeButton, INPUT_PULLUP);
pinMode(led, OUTPUT);
buttonMode = 1; // start state machine and attach this to home_position();
lastButtonMode = 1;
digitalWrite(led, LOW);
}
void loop()
{
// always check for buttonMode
buttonMode = digitalRead(modeButton);
delay(20); // low fi debouncing
if (buttonMode != lastButtonMode) {
buttonMode = digitalRead(modeButton);// debounced button read
switch (buttonMode) {
case (0): // you pressed button, think of it like a reset button
Serial.println("reset ");
home_position();
function2();
tristate = 1;
break;
case (1): // normal operation
if (tristate == 1) {
secondFunction();
}
break;
}
}
lastButtonMode = buttonMode;
}
void home_position()
{
digitalWrite(led, LOW);
Serial.println("home position");
}
void function2() {
Serial.println("function2");
Serial.println("going to second function");
}
void secondFunction() {
digitalWrite(led, HIGH);
}