First off, I am extremely new to arduino programming. In fact, I do not even own an Arduino currently. (Its OTW)
Currently only using tinkercad's web simulator to get used to programming the Arduino.
Thus, I might ask some obvious/stupid questions. I hope you can forgive me for that, haha.
My goal for this project is to create a system that do a "test" every 20 seconds. But you can also bypass the waiting time of 20 seconds, if you wanted to.
Thus, I created a feature so that when button 1 is pressed, a question is asked.
In this case the question is "Manual Testing?".
To which, the user will use button 1 for Yes or button 2 for No.
I have 2 problems.
The first is for when button 2 is pressed. What I wanted when button 2 is pressed was to resume the "main display". Which is counting down from 20 seconds. But I have no idea how to resume back to that part... I tried break; and return;, but they just gave me errors.
The second problem is that button 1 is not registering, hence the question is not displaying on the LCD, for the life of me I just can't figure out why.
If anyone can guide me on how to solve those problems, that would be greatly appreciated!!
My sketch:
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
const int buttonPin = 2;
const int button2Pin = 9;
bool optionMode = false;
bool systemBegin = false;
unsigned long debounceDelay = 50;
unsigned long lastPress = 0;
int buttonState = LOW;
int button2State = LOW;
int lastbuttonState = LOW;
int lastbutton2State = LOW;
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(button2Pin, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
buttonState = digitalRead(buttonPin);
button2State = digitalRead(button2Pin);
if (systemBegin == false)
{
lcd.print("SYSTEM STARTED");
delay(2000);
lcd.clear();
systemBegin = true;
}
if ((millis() - lastPress) > debounceDelay)
{
if (buttonState == HIGH && optionMode == false)
{
Serial.println("Option Mode is True");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Manual Testing?");
lcd.setCursor(0,1);
lcd.print("Yes | No");
optionMode = true;
lastPress = millis();
if (buttonState == HIGH && optionMode == true)
{
testingPrint();
delay(5000);
lcd.clear();
lcd.print("Completed!");
delay(2000);
lcd.clear();
optionMode = false;
lastPress = millis();
}
else if (button2State == HIGH && optionMode == true)
{
lcd.clear();
lcd.print("Returning to");
lcd.setCursor(0,1);
lcd.print("countdown");
delay(5000);
optionMode = false;
lastPress = millis();
}
}
}
while (optionMode == false)
{
lcd.clear();
for (int i = 20; i >= 0; i--)
{
lcd.setCursor(0,0);
lcd.print("Time remaining =");
lcd.setCursor(0,1);
lcd.print(i);
delay(1000);
if ( i == 10)
{
lcd.setCursor(1,1);
lcd.print(" ");
}
if (i == 0)
{
testingPrint();
delay(5000);
lcd.clear();
i = 20;
}
}
}
}
void testingPrint()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Testing in ");
lcd.setCursor(0,1);
lcd.print("progress");
}
My circuit: