Hardware Reference
In-Depth Information
void loop2()
{
i++;
Serial.print("loop2()");
Serial.println(i, DEC);
delay(1000);
}
A global variable has been added:
i
. Each time a loop function is called,
i
is
incremented, and the value is displayed. The output of this function is again a
list, alternating between
"loop1()"
and
"loop2()"
with the variable
i
incre-
menting each time.
Noncooperative Functions
Now, add something else. The variable
i
is incremented each time a loop is
called, and we would like to have a message displayed when
i
reaches the value
20. This can be achieved by adding a third function, one that looks at the value
of
i
and prints a message if the value is reached.
#include <Scheduler.h>
int i;
void setup()
{
Serial.begin(9600);
// Add "loop1" "loop2" and "loop3" to scheduling.
Scheduler.startLoop(loop1);
Scheduler.startLoop(loop2);
Scheduler.startLoop(loop3);
i = 0;
}
void loop()
{
delay(1000);
}
void loop1()
{
i++;
Serial.print("loop1(): ");
Serial.println(i, DEC);
delay(1000);
}
Search WWH ::
Custom Search