i need help with my programming code
This is a like an time game
The goal is to hold down a button for exactly 5 seconds. When you release the button, the result should be displayed in milisecounds , the number of attempts and HIGH SCORE.Messages should be displayed on an LCD. I wnt to use backlight to show activity (for exampel change color when pressed, etc.)
when I release the button I should get a result. for example that if I hold the button for 5 seconds which is 5000 milliseconds then it should appear on the display and I have 20 attempts and then the high score comes which is 20 and how much my record is +1. all this should be shown in the display. BUT if I don't hold the button for 5 seconds then there is no point but the display should show how long i pressed the button anyway. The goal is to MANAGE to hold the button down for exactly 5000 millisec/ 5 sec. also there is a point that is displayed
Something extra I would like to include is background lighting to show activity RGB (change color when pressed, ![]()
I have already started the programming and am about halfway through. this is the part I struggle a lot with and wonder if maybe someone could move it forward or help me further?
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int button = 8;
const int colorBlueR = 0;
const int colorBlueG = 0;
const int colorBlueB = 255;
const int colorGreenR = 0;
const int colorGreenG = 255;
const int colorGreenB = 0;
const int colorRedR = 255;
const int colorRedG = 0;
const int colorRedB = 0;
unsigned long buttonStart = 0;
long buttonTime = 5000;
bool started = false;
int highScore = 0;
int attempts = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
bootScreen();
delay(1000);
pinMode(button, INPUT);
}
void bootScreen()
{
lcd.setRGB(colorBlueR, colorBlueG, colorBlueB);
lcd.setCursor(0, 0);
lcd.print("5000ms TIMER" );
lcd.setCursor(0, 1);
lcd.print("PRESS TO START " );
}
void inButtonScreen()
{
lcd.setRGB(colorRedR, colorRedG, colorRedB);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("BUTTON" );
lcd.setCursor(0, 1);
lcd.print("PRESSED" );
}
void lockScreen()
{
lcd.setRGB(colorRedR, colorRedG, colorRedB);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ATTEMPTS : " );
lcd.print(attempts);
lcd.setCursor(0, 1);
lcd.print("HIGHSCORE : " );
lcd.print(highScore);
}
void loop() {
int buttonState = digitalRead(button);
if(buttonState)
{
lockScreen();
delay(10);
}
else
{