How to declare a TIMESHARING array.
DESCRIPTION
Time sharing array is used to describe how often a function will run.
On every field of the array you need an unsigned integer that declares how often that function will run, and the function name.
An example of time sharing array declaration:
TIMESHARING timeSharingArray[] = {
{500, displayMillis},
{5000,lcdBacklight},
{100,redBlink},
{100000,beep},
};
SYNTAX
<unsigned int>,<Fuction name>
<unsigned int> How often the function will run in Millis
<Function Name> The function Name.
Example #1 - Red Blink
#include
#include
InvIoT_U1 lcd(A0, A1); void VOID(){} aIoTRunTime timeSharing; TIMESHARING timeSharingArray[] = { {100,redBlink}, }; //*************************** SETUP and LOOP void setup() { lcd.print("Red Blink"); timeSharing.init(timeSharingArray, sizeof(timeSharingArray)); } void loop() { timeSharing.run(); } //*************************** TIME SHARING FUNCTIONS void redBlink() { lcd.led(!lcd.ledIs()); }
Example #2 - Mulitple Time Sharing
#include
#include
InvIoT_U1 lcd(A0, A1); void VOID(){ } aIoTRunTime timeSharing; TIMESHARING timeSharingArray[] = { {500, displayMillis}, {5000,lcdBacklight}, {100,redBlink}, {60000,beep}, }; //*************************** SETUP and LOOP void setup() { timeSharing.init(timeSharingArray, sizeof(timeSharingArray)); } void loop() { timeSharing.run(); } //*************************** TIME SHARING FUNCTIONs void displayMillis() { lcd.clear(); lcd.print("millis()="); lcd.print(millis()); } void lcdBacklight(){ lcd.setBackLight(LOW); delay(100); lcd.setBackLight(HIGH); } void redBlink() { lcd.led(!lcd.ledIs()); } void beep() { lcd.setBuzzer(5); }
SEE ALSO