const int btn_pin = 8;
const int black_pin = 9;
const int white_pin = 10;
int currentMode = 0;
int btn_state = HIGH;
int btn_last = HIGH;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(btn_pin, INPUT_PULLUP);
pinMode(black_pin, OUTPUT);
pinMode(white_pin, OUTPUT);
}
void loop() {
// The concept is that if the button changes state, the state variable "currentMode" changes
// this should only ever happen when the button changes state rather than millions of times
btn_last = btn_state;
btn_state = digitalRead(btn_pin);
if (btn_last != btn_state) { //button state changed
currentMode = currentMode == 0 ? 1 : currentMode == 1 ? 2 : 1; //allows 0 to move to 1 then cycle back and forth between 1 and 2
}
int white_state = currentMode == 1 ? HIGH : LOW; //only turn on the white light when the currentMode===1
int black_state = currentMode == 2 ? HIGH : LOW; //only turn on the black light when the currentMode===2
digitalWrite(white_pin, white_state);
digitalWrite(black_pin, black_state);
/*
Serial.println(white_state==HIGH?"white HIGH":"white LOW");
Serial.println(black_state==HIGH?"Black-HIGH":"black-LOW");
Serial.println(btn_state==LOW?"Button-LOW":"Button-HIGH");
Serial.println(currentMode==0?"mode-off":currentMode==1?"mode-1":"mode-2");
*/
}