Hi,
I'm working on a code for a project and I noticed that one piece of my code doesn't work as it should.
I'd like to write pin to LOW, connect push button between that pin and reset pin, but Arduino just doesn't write the pin LOW..
Writing the pin LOW is taking place in a function, after the loop. I've tried to write it LOW in setup, but that doesn't work either?
The interesting part is that everything is working when I use the function just on its own in a new code (in the loop), but not when I integrate it to the code where it's supposed to work.
The code as a function:
void SystemReset() {
systemreset:
if (digitalRead(RedButton) == HIGH) {
Serial.println("Checkpoint 1");
if (buttonActive == false) {
buttonActive = true;
buttonTimer = millis();
}
if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {
longPressActive = true;
lcd.setCursor(0, 0);
lcd.clear();
delay(100);
digitalWrite(51, LOW);
Serial.println("Checkpoint 2");
delay(100);
Serial.println("Long Press");
lcd.setCursor(0, 0);
lcd.print("ORANGE = RESET");
lcd.setCursor(0, 2);
lcd.print("GREEN = RETURN");
reset = 1;
}
Serial.println("Checkpoint 3");
}
else {
if (buttonActive == true) {
if (longPressActive == true) {
longPressActive = false;
}
else {
Serial.println("Short press");
}
buttonActive = false;
}
}
if((reset == 1) && (digitalRead(STARTbutton) == HIGH)){
digitalWrite(51, HIGH);
lcd.clear();
Serial.println("Green pressed");
reset = 0;
lcd.clear();
return;
}
goto systemreset;
}
As you can see I've set some Checkpoints up for Serial monitor and it passes the digitalWrite(51, LOW), but doesn't do anything..
And here's to code in a loop:
void loop() {
if (digitalRead(RedButton) == HIGH) {
if (buttonActive == false) {
buttonActive = true;
buttonTimer = millis();
}
if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {
longPressActive = true;
lcd.setCursor(0, 0);
lcd.clear();
delay(100);
digitalWrite(51, LOW);
Serial.println("Long Press");
lcd.setCursor(0, 0);
lcd.print("Orange = Reset");
lcd.setCursor(0, 2);
lcd.println("Green = Return");
reset = 1;
}
}
else {
if (buttonActive == true) {
if (longPressActive == true) {
longPressActive = false;
} else {
Serial.println("Short press");
}
buttonActive = false;
}
}
if((reset == 1) && (digitalRead(GreenButton) == HIGH)){
digitalWrite(51, HIGH);
lcd.clear();
Serial.println("Green pressed");
reset = 0;
lcd.clear();
}
}
The bottom version is working fine, but the top version not at all..
Any help would be appreciated.
Thanks