void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello");
pinMode(23, OUTPUT);
pinMode(32, INPUT_PULLUP);
digitalWrite(23, LOW);
}
void togglePin(int pin) {
static uint8_t pin_state = LOW;
if (pin_state == LOW) {
digitalWrite(pin, HIGH);
pin_state = HIGH;
} else {
digitalWrite(pin, LOW);
pin_state = LOW;
}
}
bool check_button(int pin) {
static bool pause = false;
static bool res = false;
static unsigned long time = 0;
if((digitalRead(32) == LOW) && (!pause)) {
res = !res;
pause = true;
time = millis();
} else if (pause) {
if (millis() > time + 500) {
pause = false;
}
}
return res;
}
void loop() {
uint8_t start_blink = LOW;
start_blink = check_button(32);
if (start_blink == HIGH) {
if (millis() % 500 == 0) {
togglePin(23);
}
} else {
digitalWrite(23, LOW);
}
}