I am pretty new on Arduino programming but I have experiences with other developing approaches. I kindly ask you to help me with my problem.
I have a led diode and a push button in my circuit. I would like to create a script wich will allow to users to select more then one mode of led blinking using the push button.
For example: After first pressed on the button led will turn on. Then second pressed will change mode and led will start blinking and after third push the led will turn off.
The problem is when the program comes to second mode (led blinking). There is one second delay between turn on and turn off and then when is the program in delay mode push button is not accessible. As I know arduino doesn't support multithreading. Is there any other options how to solve this?
I would like to led will blinking and after push button will be pressed the led will turn off.
mango89:
For example: After first pressed on the button led will turn on. Then second pressed will change mode and led will start blinking and after third push the led will turn off.
The problem is when the program comes to second mode (led blinking). There is one second delay between turn on and turn off and then when is the program in delay mode push button is not accessible. As I know arduino doesn't support multithreading. Is there any other options how to solve this?
Such problems can always be solved by strictly following the IPO programming model:
Input
Processing
Output
In an Arduino sketch your loop() function would look like that:
void loop()
{
input();
processing();
output();
}
And it would be up to you to write three functions to make your program work in "cooperative multitasking".
input() function reads all the input
processing() function does all the logical processing
output() function sends all the logical output to the world outside the Arduino
The function "delay()" is a blocking function, which is totally forbidden in any cooperative multitasking application.