Hi there,
first of all, hello to everyone; I am the newbie to this forum and to arduino.
I guess my question has been discussed, but I am not able to find a suitable answer for me.
To be honest, I not sure, what to search for.
So here comes my first question:
Which possible solutions are there for handle multiple task in the loop at different times?
To explain:
Currently I have a LCD Display, a SD and some buttons connected to the arduino.
And I would like to connect a MPU-6050, but this just by the way....
I am working with Modulo in my loop, but I have the feeling, that there could be a better way.
For example:
- Check for a toggeled switch/button
- Update the display often
- Write on SD from time to time
Would be nice if you guys share some ideas or docu-links on howto handle the loop effective.
(I'm working with c++ on PC and there you have SIGNAL/SLOT mechanism, I have to readjust to the concept)
Thanks in advance,
Rene
What I'm doing now is:
long loopCounter=0;
void loop()
{
check_if_switch_interupt_was_toggled();
if ( loopCounter % 5000 == 0)
{
updateLCD();
}
if ( loopCounter % 20000 == 0)
{
if (newData)
{
writeSD();
}
}
loopCounter++;
//reset to prevend overflow
if (loopCounter>1000000)
{
loopCounter=0;
}
}