I am working on a hobby project - a stopwatch with lcd display. A switch (digitalRead(11)== HIGH) is used for starting the stopwatch and a push button (digitalRead(12)== HIGH) is used to stop the stopwatch if it is running. The problem is with the reset that is done with a start-reset switch (digitalRead(11)== LOW). The "else if" statement for reset is never executed although the conditions are fulfilled as the logic for this conditions are similar to one for STOP statement.
I'd be inclined to put some serial prints at the top of loop() and display the values of the things that take part in all those ifs to verify that they are what you think they are.
pinMode(start_reset_pin, INPUT); // sets the digital pin 11 as output
It most certainly does not!
The comment "//sets the digital pin 11 as output" is not correct. The pinMode() of pin 11 is correctly set to INPUT.
PaulS:
Which one of the 4 else if statements would that be?
I am having problems with the following else if statement (everything else is working ok):
else if ((sw_millis.state() == StopWatch::STOPPED) && (digitalRead(start_reset_pin) == LOW))
{
// reset - THIS IS NEVER EXECUTED???
sw_millis.reset();
}
PaulS:
Frankly, nested if statements are easier to see (and debug) the logic of than all the compound if statements you are using.
I am more of a hobby programmer so I would ask you, if you can show me an example of nested if statements as I don't know what are you reffering to.
JimboZA:
I'd be inclined to put some serial prints at the top of loop() and display the values of the things that take part in all those ifs to verify that they are what you think they are.
JimboZA:
I'd be inclined to put some serial prints at the top of loop() and display the values of the things that take part in all those ifs to verify that they are what you think they are.
The use of serial prints was my first step. With a bit of mind work I found the improvized solution to call function reset() every time when the first statement is executed (ready). The doubt I have is because I use similar logic for stoping the stopwatch and it works OK, but I am having problems with stopwatch reset.
You have a number of conditions you want to check for. Is the stopwatch running? If it is, then stop makes sense. If it isn't, then the state of the stop switch doesn't matter. So, the outer if statement should be:
In the "it is running" block, you have to check for other events of interest (stop, reset). In the else block, you check for events of interest (start):