'I want to run two function simultaneously in program In Arduino
void a(){
delay(3000)
# other statement
}
void b(){
delay(3000)
# other statement
}
Now I want to run these function in parallel but I when I call first function then it should cancel the delay time of other function and other functionality of function b and vice versa. My aim to run it in parallel.
Solution 1:[1]
As a real Arduino does not run an operating system, you have to do some sort of multitasking by yourself. Refrain from writing blocking functions. Your function void a() should look similar to:
void a() {
static unsigned long lastrun;
if (millis() - lastrun >= 3000) {
lastrun=millis();
// non-blocking code to be executed once every 3 sec
}
}
As Arduino is written in C++, feel free to create a timer class doing this for you (and avoid static or global variables) But that's probably beyond your question.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
