Hey guys.. I am learning to use push button..
I know how it works.
But the problem is I want to implement this button in my program... Where there will be some time will be given for the user to press that button, if the user doesn't press the button the program will continue its execution, and if the user presses the button the program starts again from beginning.
I don't know how to achieve this.
Hope you people can help
Use millis() for the timing.
Save its value when the timing period starts and start reading the input in a while loop. If a button press is detected set a variable to flag that it has happened. The exit conditions for the while loop will be detection of a button press or millis() - startTime being greater than the required period.
On exit from the while loop the value of the button press detected variable will tell you the reason why the loop was exited and you can take appropriate action.
if the user doesn't press the button the program will continue its execution
Continue executing what?
user presses the button the program starts again from beginning.
The beginning of what?
Some CLEAR requirements are necessary before you can write code.
you have already such a button on the board - it's labeled RESET - isn't that what you want to do?
J-M-L:
you have already such a button on the board - it's labeled RESET - isn't that what you want to do?
I want another button.. That only to be used within that given time.
Anket:
I want another button.. That only to be used within that given time.
The solution is in Reply #1
...R
I m new in programming so I cant understand what he told. Can some one do a syntax of what he told.. That will be really helpful
Anket:
I m new in programming so I cant understand what he told. Can some one do a syntax of what he told.. That will be really helpful
This is not real code and will not compile but may help you understand
set buttonWasPressed HIGH
set startTime equal to millis()
while millis() - startTime less than 3000
set buttonWasPressed equal to digitalRead(buttonPin)
if buttonWasPressed equals LOW
exit the while loop
end of if
end of while
if buttonWasPressed equals LOW
take action
end of if
else
take other action
end of else
Where there will be some time will be given for the user to press that button
How much time? A year?
Anket:
I m new in programming so I cant understand what he told.
That is reasonable. But until you told us that you don't understand it we had assumed you did.
If you see some advice that you don't understand you should say so immediately. Asking question is wise. Staying silent when you don't understand is stupid.
...R