This is my code for a school project but i want to change the displayed Miliseconds to seconds
instead of showing (Your reaction speed is 325 ms) , i want it to show (Your reaction speed is 3.25 seconds)
int red = 5;
int yellow = 4;
int green = 3;
int button = 8;
long randno;
// Assign names to the port
void setup()
{
Serial.begin(9600); //enabling serial communication
// set initial LED state
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
pinMode(button,INPUT_PULLUP);
Serial.println("WELCOME TO REACTION TIMER"); // Display in serial monitor on start-up
}
void loop()
{
unsigned long count = 0;
unsigned long butthold = 0;
char buttvalue;
randno = random(1000,5000); //function to random a time from 1Sec - 5Sec
digitalWrite(green,HIGH); //Light up Green
delay(randno); // use the command declared on top, random a time from 1Sec - 5Sec
digitalWrite(red,HIGH); //after a random time, light up red
digitalWrite(green,LOW); //off green
do
{
butthold++; //increment of button pressed
buttvalue = digitalRead(button); //read value of button
}
while(buttvalue == LOW); //if button is pressed
do
{
buttvalue = digitalRead(button); // read value of pin 8 and assign to button
delay(1); //ensure the loop takes 1 Miliseconds
count++; //increase counter by 1
}
while(buttvalue == HIGH); //if button is not pressed
if(butthold > 1) //if button is pressed more than once before light change
{
Serial.println("HEY DONT CHEAT! Restarting....Rdy?"); //print dont cheat
digitalWrite(red,LOW); //and red led remains on
}
else //if everything is fine and button is pressed
{
digitalWrite(red,LOW); //off red led
digitalWrite(yellow,HIGH); //on yellow led
Serial.print("Your reaction speed is: "); //display text into serial monitor
Serial.print(count); //display the counted timing
Serial.println(" MiliSeconds"); //display text into serial monitor
delay(2000); // after displaying, delay 2 Sec
Serial.println("Next round is starting....Get Ready"); //display text into serial monitor
digitalWrite(yellow,LOW);
} // after this end this loop and go back to the start of loop
}