I have an Uno which counts laps and has an elapsed time that displays on a 20x4 LCD via i2c.
I would like to have a button which resets the "count" which DOES work, and another button that resets the timer. This does NOT work... and I have tried many iterations on how.
Also, I would like to display a quantity below "Lap Count" which displays laps per hour.... I have yet to make this work and not sure how.
Fairly novice here so any help is much appreciated.
What I would like to do, is have the button connected to DIO5, on press, reset the variables elapsedSecDisp, elapsedMinDisp, and elapsedHr. I have separate display values as In the code, I am using the non Disp values to calculate other values, ie elapsedSec is used to calculate elapsedMin, and elapsedMin is used to calculate elapsedHr, but then I haven't figured out how to say, minutes hits 60, +1 on hours and reset minutes.
Maybe there is a better way to do that too- but that is for an efficiency and size cleanup later. For now I would like to see the reset buttons work as expected which shouldn't be too hard.
Have you confirmed with a simple sketch that the button is wired correctly and that a press of the button is read as you intend? You could have a hardware problem.
cattledog:
Have you confirmed with a simple sketch that the button is wired correctly and that a press of the button is read as you intend? You could have a hardware problem.
It is configured identical to the other button, resetCount which does work. I have tried different buttons, and resistors etc, there is no reason it shouldn't work. Depending on some changes I tried on the code, it kind of worked (ie, would set to zero) but then it would continue counting where it was at before... such as 33, 34, 35, 00, 36, 37... etc so it wasn't fully resetting.
If I do a digital write to LED it does work. So for whatever reason it isn't resetting the actual variable.
IN5 Is the button that isn’t working as intended
IN6 takes the signal out from the infrared line tracking module.
IN9 Is the counter reset button that does work.
EDIT:
Sorry, the file was attached but was too large, and I have a limit to how often I can post apparently. Limited to once every 5 minutes. Any way to remove that?
Thanks for being patient with the new guy to the forum.
I hadn't even looked at C# or an Arduino board before last Sunday, so still mastering a few things but have worked with low voltage, basic web development and computers in a professional capacity the past 12 years or so.
backwoodsjack:
if (button2State == HIGH) {
if (elapsedSec >= 0) {
elapsedSecDisp = 0;
elapsedMinDisp = 0;
elapsedHr = 0;
why do u care if elapsedSec>=0 ??
just reset everything...
have u tried that..
Removed the IF statements, and I still do not get anything out of the resetTime button, I changed the INT values to switch the roles of both buttons and the second button worked for the resetCount variable as well, the other did not work for the resetTime function.
Is it not wired correctly? (see uploaded picture a couple posts back....)
Good move exchanging the buttons to prove that you have a hardware problem.
Rotate the button which does not work by 90 degrees. These buttons have two legs which are always connected and two that are switched. You are wired across a connected pair. If you can't test the configuration of the button with a multimeter, it always works to wire diagonally across the button.
It also more common to use INPUT_PULLUP mode instead of external pull down resisitors. It simplifies the wiring. One wire from a button leg to the input pin which is set to INPUT_PULLUP and the other wire from diagonally across the switch to ground. The logic is reversed with not pressed == HIGH and pressed == LOW.
cattledog:
Good move exchanging the buttons to prove that you have a hardware problem.
Rotate the button which does not work by 90 degrees. These buttons have two legs which are always connected and two that are switched. You are wired across a connected pair. If you can’t test the configuration of the button with a multimeter, it always works to wire diagonally across the button.
It also more common to use INPUT_PULLUP mode instead of external pull down resisitors. It simplifies the wiring. One wire from a button leg to the input pin which is set to INPUT_PULLUP and the other wire from diagonally across the switch to ground. The logic is reversed with not pressed == HIGH and pressed == LOW.
No- I swapped the buttons on the breadboard, and nothing changed (BOTH buttons worked on the input set to resetCount, exactly as placed on the board). I modified the code to switch the input pins around and the issue followed the variable, not the button.
Not sure I follow you on the input_pullup, can you reference a page or share a diagram as to what you mean?