-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new file: examples/multi-blink/multi-blink.ino new file: examples/multi-toggle/multi-toggle.ino new file: examples/toggle/toggle.ino modified: src/tcone.cpp modified: src/tcone.h
- Loading branch information
1 parent
76f8a8e
commit 97ccdc1
Showing
6 changed files
with
206 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// The device is equipped with three LED lights, each with a distinct blinking pattern. | ||
// The RED LED blinks at a frequency of 500ms ON and 500ms OFF, | ||
// the YELLOW LED blinks at a frequency of 1000ms ON and 1000ms OFF, | ||
// and the GREEN LED blinks at a frequency of 2000ms ON and 2000ms OFF. | ||
|
||
#include "TCone.h" | ||
|
||
// Define the task periodic in milliseconds | ||
#define TASK_PERIOD 1 | ||
// Define the number of tasks | ||
#define TASK_SIZE 3 | ||
|
||
// TaskMember declaration | ||
// Single: | ||
// taskMember = {duration, manualReset, enable}; | ||
// Array: | ||
// taskMembers[N] = { | ||
// {duration_0, manualReset_0, enable_0}, | ||
// {duration_1, manualReset_1, enable_1}, | ||
// {..., ..., ...} | ||
// {duration_N-1, manualReset_N-1, enable_N-1}, | ||
// }; | ||
TaskMember taskMember[TASK_SIZE] = { | ||
{500}, | ||
{1000}, | ||
{2000} | ||
}; | ||
|
||
// Task declaration | ||
// TCone Task (period, *tasks, size); | ||
// Para: | ||
// uint16_t period - in milliseconds | ||
// TaskMember *tasks - Pointer of TaskMember | ||
// uint16_t size - Number of Tasks | ||
// It is mandatory to name the TCone declaration as "Task". No other name should be used. | ||
TCone Tasks(TASK_PERIOD, taskMember, TASK_SIZE); | ||
|
||
const uint8_t ledPins[TASK_SIZE] = {4, 3, 2}; | ||
|
||
// OnTaskElapsed Function declaration with id and TaskMember | ||
void OnTaskElapsed(volatile uint8_t id, volatile TaskMember *member); | ||
|
||
void setup() { | ||
// Set the pin mode of "LED_BUILTIN" as an output | ||
for (uint8_t index = 0; index < TASK_SIZE; index++) { | ||
pinMode(ledPins[index], OUTPUT); | ||
} | ||
|
||
// Implement a callback function that can be triggered when the task's allocated time has elapsed. | ||
Tasks.callbackOnTaskElapsed(OnTaskElapsed); | ||
|
||
// It is imperative to utilize the begin() function to internally configure Timer0 and commence its operation. | ||
Tasks.begin(); | ||
} | ||
|
||
void loop() { | ||
// Use a loop to write the value to LEDs to represent the state status. | ||
for (uint8_t index = 0; index < TASK_SIZE; index++) { | ||
// Write the state value to LED. | ||
digitalWrite(ledPins[index], taskMember[index].state); | ||
} | ||
} | ||
|
||
void OnTaskElapsed(volatile uint8_t id, volatile TaskMember *member) { | ||
// Toggle the state | ||
member->state = !member->state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// The LED_BUILTIN exhibits a continuous blinking pattern | ||
// with a frequency of 500ms in the ON state followed by 500ms in the OFF state. | ||
|
||
#include "TCone.h" | ||
|
||
// Define the task periodic in milliseconds | ||
#define TASK_PERIOD 1 | ||
// Define the number of tasks | ||
#define TASK_SIZE 3 | ||
|
||
// TaskMember declaration | ||
// Single: | ||
// taskMember = {duration, manualReset, enable}; | ||
// Array: | ||
// taskMembers[N] = { | ||
// {duration_0, manualReset_0, enable_0}, | ||
// {duration_1, manualReset_1, enable_1}, | ||
// {..., ..., ...} | ||
// {duration_N-1, manualReset_N-1, enable_N-1}, | ||
// }; | ||
TaskMember taskMember[TASK_SIZE] = { | ||
{20}, | ||
{20}, | ||
{20} | ||
}; | ||
|
||
// Tasks declaration | ||
// Para: | ||
// uint16_t period - in milliseconds | ||
// TaskMember *tasks - Pointer of TaskMember | ||
// uint16_t size - Number of Tasks | ||
// It is mandatory to name the TCone declaration as "Tasks". No other name should be used. | ||
TCone Tasks(TASK_PERIOD, taskMember, TASK_SIZE); | ||
|
||
const uint8_t buttonPins[TASK_SIZE] = {A3, A2, A1}; | ||
const uint8_t ledPins[TASK_SIZE] = {4, 3, 2}; | ||
bool toggles[TASK_SIZE]; | ||
|
||
|
||
void setup() { | ||
// Set the pin mode of "LED_BUILTIN" as an output | ||
for (uint8_t index = 0; index < TASK_SIZE; index++) { | ||
pinMode(buttonPins[index], INPUT_PULLUP); | ||
pinMode(ledPins[index], OUTPUT); | ||
} | ||
|
||
Tasks.manualReset(true); | ||
// It is imperative to utilize the begin() function to internally configure Timer0 and commence its operation. | ||
Tasks.begin(); | ||
} | ||
|
||
void loop() { | ||
// Write the state value to LED_BUILTIN. | ||
|
||
for (uint8_t index = 0; index < TASK_SIZE; index++) { | ||
if (taskMember[index].done) { | ||
bool prevState = taskMember[index].state; | ||
taskMember[index].state = digitalRead(buttonPins[index]); | ||
if (prevState & !taskMember[index].state) { | ||
toggles[index] = !toggles[index]; | ||
digitalWrite(ledPins[index], toggles[index]); | ||
} | ||
Tasks.reset(index); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// The LED_BUILTIN exhibits a continuous blinking pattern | ||
// with a frequency of 500ms in the ON state followed by 500ms in the OFF state. | ||
|
||
#include "TCone.h" | ||
|
||
#define BUTTON 12 | ||
// Define the task periodic in milliseconds | ||
#define TASK_PERIOD 1 | ||
// Define the number of tasks | ||
#define TASK_SIZE 1 | ||
|
||
// TaskMember declaration | ||
// Single: | ||
// taskMember = {duration, manualReset, enable}; | ||
// Array: | ||
// taskMembers[N] = { | ||
// {duration_0, manualReset_0, enable_0}, | ||
// {duration_1, manualReset_1, enable_1}, | ||
// {..., ..., ...} | ||
// {duration_N-1, manualReset_N-1, enable_N-1}, | ||
// }; | ||
TaskMember taskMember = {10}; | ||
|
||
// Tasks declaration | ||
// Para: | ||
// uint16_t period - in milliseconds | ||
// TaskMember *tasks - Pointer of TaskMember | ||
// uint16_t size - Number of Tasks | ||
// It is mandatory to name the TCone declaration as "Tasks". No other name should be used. | ||
TCone Tasks(TASK_PERIOD, &taskMember, TASK_SIZE); | ||
|
||
bool toggle; | ||
|
||
void setup() { | ||
pinMode(BUTTON, INPUT_PULLUP); | ||
// Set the pin mode of "LED_BUILTIN" as an output | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
|
||
Tasks.manualReset(true); | ||
// It is imperative to utilize the begin() function to internally configure Timer0 and commence its operation. | ||
Tasks.begin(); | ||
} | ||
|
||
void loop() { | ||
// Write the state value to LED_BUILTIN. | ||
if (taskMember.done) { | ||
bool prevState = taskMember.state; | ||
taskMember.state = digitalRead(BUTTON); | ||
if (prevState & !taskMember.state) { | ||
toggle = !toggle; | ||
digitalWrite(LED_BUILTIN, toggle); | ||
} | ||
Tasks.reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters