I have recently decided to amke a game with a lcd 16X2 fnd two buttons. The goal of the game is to score as many clicks as possible. The problem is that I don't understand how to make the second millis for the game timer. Help me please.
Welcome to the forum
Thank you for using code tags in your first post
What exactly do you want the "second millis" to do ?
Incidentally, it seems very clumsy to use millis() for timing in the sketch then to use delay(). I also note that the delay(900000) only occurs if player 2 wins. Is that what you intended ?
Thank you.
I have finally understood my mistake in delay in the end of code.
I wanted to make something like ending by using delay.
Could you help me with this?
One problem is that you have the game timer inside the 'if' for button2 being pressed. That mean's that if button2 is never pressed, the game can never end.
Change this part:
if (button2 == 1 && millis() - debounce > 110)
{
debounce = millis();
numbcount2++;
lcd.setCursor(9, 1);
lcd.print(numbcount2);
if (millis() - time > 10000)
{
if (button2 == 1 && millis() - debounce > 110)
{
debounce = millis();
numbcount2++;
lcd.setCursor(9, 1);
lcd.print(numbcount2);
}
if (millis() - time > 10000)
{
(That will leave you with an extra '}' near the bottom that you will have to remove.)
Your delay() is only in the case Player 2 wins. Change it to:
lcd.print("PLAYER 2");
lcd.setCursor(6, 1);
lcd.print("WINS");
}
delay(900000);
// If you want the game to re-start after the
// huge delay, this is where you would set
// 'time' to millis() to re-start the timer.
See the "StateChangeDetection" example for how to act when the button CHANGES from unpressed to pressed, rather than repeating for as long as the button is pressed.