Im trying to create a program with this statement.
Develop a program such that if you press a touch sensor an LED will light up once, and if the sensor is pressed again within 5 seconds it blinks twice. After the button is pressed the second time (or 5 seconds pass), the program goes back to its original condition (waiting for the first press of the sensor).
I can make it blink twice, but I cannot get the condition to go back after 5 seconds.
what am I doing wrong?
That problem statement makes this look like a class assignment. We don’t do class assignments here.
I sure hope that the btn pin is wired to a pulldown resistor and to a N.O. pushbutton switch that has its other side connected to Vcc but without a schematic, who is to know?
vaj4088:
That problem statement makes this look like a class assignment. We don't do class assignments here.
I sure hope that the btn pin is wired to a pulldown resistor and to a N.O. pushbutton switch that has its other side connected to Vcc but without a schematic, who is to know?
The wiring is fine, it blinks when i press the button, and then blinks twice when i press it again and it resets. However i cannot make it reset so that it doesnt blink twice after 5 seconds. I do not know how to do that, and cannot find anything in the millis() thread
joeman783:
I do not know how to do that, and cannot find anything in the millis() thread
You didn't find ANYTHING in that thread? Then you need to study it harder. You can find from milis() what time it was when the button was first pressed. At any later point you can compare that time to the current time to see if 5 seconds have passed. That sounds pretty useful to me.
To help you a bit - ask yourself when you do while(timez - timex < 5000) what is changing timez In the while loop…
I would not approach the problem this way though, your blinking is basically simple:
In the loop, Upon press of the button, blink twice if the previous press was less than 5 seconds ago and you did not already blink twice last time, else Blink once