1. According to datasheet, the MKR1000 with Cortex-M0 signle-core SoC can run in normal operation sequence fairly well, ie, in serial running mode. Each code runs one by one, the interrupt can be attached for unexpected incident.
But this in not fit for the BWaC project, thread would be better for multi-sensors and selective one-to-more control logic.
Therefore, ScheduleTable is used as framework for this project. There are different process running, until the preset signal is triggered.
2. The schedule table is a data structure to schedule actions along a timeline. A schedule table has a period and can process one or more actions. The library can be download from arduino library management with key search work of "schedule table".
First, include the header file,
#include <ScheduleTable.h>
Then, creating a schedule table. Typical form like this,
SchedTable<2> blinkLED(500);
Schedule one table with 2 actions and a 500ms period. This is done by using a SchedTable class instance. By default the time base is in milliseconds.
or,
SchedTable<2> blinkLED(10,50);
Schedule the timebase of the schedule table to 50ms so that period is now expressed in multiple of 50ms.
Next, adding actions and start a schedule table . The functions called by the schedule table. An action is a function that returns nothing and has no argument. The ledOn() and ledOn() are function to run on the time scheduled.
blinkLED.at(200,ledOn); blinkLED.at(250,ledOff); ... ... blinkLED.start();
In the loop(), update the Schedule Table accordingly.
ScheduleTable::update(); ... ...
Finally, your can stop the schedule table
blinkLED.stop();
or let it stops on preset cycles like, print hello 10 times.
helloCycle.start(10);
3. Here is the example of print hello 10 times,
#include <ScheduleTable.h> SchedTable<1> helloCycle(1000); void hello() { static byte count = 0; Serial.print(++count); Serial.print(" Hello, MKR1000 "); Serial.println(millis()); } void setup() { Serial.begin(9600); helloCycle.at(1000,hello); helloCycle.start(10); } void loop() { ScheduleTable::update();}
4. Here is my framework. The core process supervises the microphone module for control signal and screens for valid Whistle command. The sensors and actuators polling the room status in schedule table even some are male-functional. Each command read the sensor or run the curator like servo or motor.
Any modification of the hardware would not interfere with other part of the codes.
Here is the diagram to be used in the program.