//Timer2
void setup()
{
Serial.begin(9600);
Serial.println("Enter seconds to time");
}
void loop()
{
timer();
}
void timer()
{
if (Serial.available()> 0)
{
float timeInput = Serial.read(); // Take input from serial monitor.
timeInput = timeInput - 48; // Todo: for some reason processor adds 48 to input, this corrects that.
timeInput = timeInput * 1000; //Converts time input to milliseconds.
Serial.println(timeInput/1000);
delay(timeInput); // Counts down to zero timeInput.
Serial.println("Timer Done!");
}
}
There are two problems I am having with this sketch. When I input a number of seconds to count down, the compiler adds 48 to it. Further, if I input a two digit number such as 12, it treats the 1 then the 2
as separate entries. The sketch does work for a single-digit entry. Thanks.