Hello,
I just recently learned of Arduino and I want to tackle a project. That being said, I've read the basics and am a novice coder but I want to dive into this. I am trying to do a few things.
4 buttons need to be input in the proper sequence to trigger an event - display a 4 digit number on LCD
If the sequence is input incorrect trigger a different event - display on the LCD a different message
With each button press that is correct I want an LED to stay lit
If an incorrect button is pushed LED's turn off
I want the code entering process to reset itself if nothing happens for 10 seconds
Lastly I want the display to shut off after 1 minute
So far here is what I have for code, this is for 1 button working it probably isnt even simplified the best way possible, layout to follow........
Using an ELEGOO UNO R3
int ledPin = 5;
int switchPin = 2;
boolean lastButton = LOW;
boolean ledOn = false;
boolean currentButton = LOW;
// put your setup code here, to run once:
void setup()
{
//initialize pins as outputs
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
// put your main code here, to run repeatedly:
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn = !ledOn;
//!inverts the last call so if it was true now false
}
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}