изменила форматирование. Добавила автовыбор ножек в зависимости от выбранной платы

This commit is contained in:
KLASSENTS 2025-03-27 13:55:05 +07:00
parent 78ef98a74d
commit f3df27f5fc
12 changed files with 261 additions and 268 deletions

View File

@ -14,11 +14,6 @@ void setup() {
// initialize serial communication at 9600 bits per second: // initialize serial communication at 9600 bits per second:
Serial.begin(9600); Serial.begin(9600);
Serial.println("Hello");
while (!Serial) {
; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
}
// Semaphores are useful to stop a Task proceeding, where it should be paused to wait, // Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
// because it is sharing a resource, such as the Serial port. // because it is sharing a resource, such as the Serial port.
@ -32,20 +27,20 @@ void setup() {
// Now set up two Tasks to run independently. // Now set up two Tasks to run independently.
xTaskCreate( xTaskCreate(
TaskDigitalRead TaskDigitalRead,
, "DigitalRead" // A name just for humans "DigitalRead", // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater 128, // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task NULL, // Parameters for the task
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. 2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle NULL); // Task Handle
xTaskCreate( xTaskCreate(
TaskAnalogRead TaskAnalogRead,
, "AnalogRead" // A name just for humans "AnalogRead", // A name just for humans
, 128 // Stack size 128, // Stack size
, NULL //Parameters for the task NULL, // Parameters for the task
, 1 // Priority 1, // Priority
, NULL ); //Task Handle NULL); // Task Handle
// Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started. // Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
} }
@ -53,7 +48,6 @@ void setup() {
void loop() void loop()
{ {
// Empty. Things are done in Tasks. // Empty. Things are done in Tasks.
Serial.println("ping");
} }
/*--------------------------------------------------*/ /*--------------------------------------------------*/
@ -64,13 +58,17 @@ void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a
{ {
/* /*
DigitalReadSerial DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor Reads a digital input on pin pushButton, prints the result to the serial monitor
This example code is in the public domain. This example code is in the public domain.
*/ */
#ifdef BTN_BUILTIN
// digital pin 2 has a pushbutton attached to it. Give it a name: uint8_t pushButton = BTN_BUILTIN;
#elif (defined(ARDUINO_ELSOMIK))
uint8_t pushButton = P0_0;
#else
uint8_t pushButton = 2; uint8_t pushButton = 2;
#endif
// make the pushbutton's pin an input: // make the pushbutton's pin an input:
pinMode(pushButton, INPUT); pinMode(pushButton, INPUT);
@ -93,13 +91,12 @@ void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
} }
vTaskDelay(1); // one tick delay (15ms) in between reads for stability vTaskDelay(1); // one tick delay (10ms) in between reads for stability
} }
} }
void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a Task. void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a Task.
{ {
for (;;) for (;;)
{ {
// read the input on analog pin 0: // read the input on analog pin 0:
@ -118,6 +115,6 @@ void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
} }
vTaskDelay(1); // one tick delay (15ms) in between reads for stability vTaskDelay(1); // one tick delay (10ms) in between reads for stability
} }
} }

View File

@ -12,6 +12,14 @@
// Define a Array // Define a Array
int pinReadArray[4]={0,0,0,0}; int pinReadArray[4]={0,0,0,0};
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
//Function Declaration //Function Declaration
void TaskBlink(void *pvParameters); void TaskBlink(void *pvParameters);
void TaskAnalogReadPin0(void *pvParameters); void TaskAnalogReadPin0(void *pvParameters);
@ -33,7 +41,6 @@ void setup() {
arrayQueue=xQueueCreate(10, // Queue length arrayQueue=xQueueCreate(10, // Queue length
sizeof(int)); // Queue item size sizeof(int)); // Queue item size
if(arrayQueue!=NULL){ if(arrayQueue!=NULL){
// Create task that consumes the queue if it was created. // Create task that consumes the queue if it was created.
xTaskCreate(TaskSerial, // Task function xTaskCreate(TaskSerial, // Task function
"PrintSerial", // Task name "PrintSerial", // Task name
@ -86,7 +93,7 @@ void TaskAnalogReadPin0(void *pvParameters){
* https://www.freertos.org/a00117.html * https://www.freertos.org/a00117.html
*/ */
xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY); xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -106,7 +113,7 @@ void TaskAnalogReadPin1(void *pvParameters){
* https://www.freertos.org/a00117.html * https://www.freertos.org/a00117.html
*/ */
xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY); xQueueSend(arrayQueue,&pinReadArray,portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -123,11 +130,6 @@ void TaskSerial(void *pvParameters){
// Init Arduino serial // Init Arduino serial
Serial.begin(9600); Serial.begin(9600);
// Wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
while (!Serial) {
vTaskDelay(1);
}
for (;;){ for (;;){
if(xQueueReceive(arrayQueue,&pinReadArray,portMAX_DELAY) == pdPASS ){ if(xQueueReceive(arrayQueue,&pinReadArray,portMAX_DELAY) == pdPASS ){
Serial.print("PIN:"); Serial.print("PIN:");
@ -149,12 +151,12 @@ void TaskSerial(void *pvParameters){
*/ */
void TaskBlink(void *pvParameters){ void TaskBlink(void *pvParameters){
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN,OUTPUT); pinMode(blink_pin,OUTPUT);
digitalWrite(LED_BUILTIN,LOW); digitalWrite(blink_pin,LOW);
for (;;){ for (;;){
digitalWrite(LED_BUILTIN,HIGH); digitalWrite(blink_pin,HIGH);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
digitalWrite(LED_BUILTIN,LOW); digitalWrite(blink_pin,LOW);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
} }
} }

View File

@ -1,24 +0,0 @@
/*
* Example of FreeRTOS configASSERT macro
* https://www.freertos.org/a00110.html#configASSERT
*/
#include <Arduino_FreeRTOS.h>
const bool valueToAssert = true;
// The setup function runs once when you press reset or power the board
void setup() {
// Assert value is true, execution doesn't stop.
configASSERT(valueToAssert == true);
// Assert value is false, FreeRTOS execution stops and start to blink main led two times with 4 second cycle.
configASSERT(valueToAssert == false);
}
void loop()
{
// Empty. Things are done in Tasks.
}

View File

@ -4,32 +4,36 @@
void TaskBlink( void *pvParameters ); void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters ); void TaskAnalogRead( void *pvParameters );
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
// the setup function runs once when you press reset or power the board // the setup function runs once when you press reset or power the board
void setup() { void setup() {
// initialize serial communication at 9600 bits per second: // initialize serial communication at 9600 bits per second:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
}
// Now set up two tasks to run independently. // Now set up two tasks to run independently.
xTaskCreate( xTaskCreate(
TaskBlink TaskBlink,
, "Blink" // A name just for humans "Blink", // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater 128, // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL NULL,
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. 2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); NULL);
xTaskCreate( xTaskCreate(
TaskAnalogRead TaskAnalogRead,
, "AnalogRead" "AnalogRead",
, 128 // Stack size 128, // Stack size
, NULL NULL,
, 1 // Priority 1, // Priority
, NULL ); NULL);
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
} }
@ -51,34 +55,18 @@ void TaskBlink(void *pvParameters) // This is a task.
Blink Blink
Turns on an LED on for one second, then off for one second, repeatedly. Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO Most boards have an on-board LED you can control. You can use it via LED_BUILTIN macro.
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care If there is no led on board, you can set different pin to blink_pin variable.
of use the correct LED pin whatever is the board used.
The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute
the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX.
e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc.
If you want to know what pin the on-board LED is connected to on your Arduino model, check
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
*/ */
// initialize digital LED_BUILTIN on pin 13 as an output. // initialize blink_pin as an output.
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) // A Task shall never return or exit. for (;;) // A Task shall never return or exit.
{ {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(blink_pin, HIGH); // turn the pin on (HIGH is the voltage level)
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW digitalWrite(blink_pin, LOW); // turn the pin off by making the voltage LOW
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
} }
} }
@ -91,7 +79,7 @@ void TaskAnalogRead(void *pvParameters) // This is a task.
AnalogReadSerial AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor. Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. Attach the center pin of a potentiometer to pin A0, and the outside pins to +3V3 and ground.
This example code is in the public domain. This example code is in the public domain.
*/ */

View File

@ -15,8 +15,15 @@
*/ */
QueueHandle_t integerQueue; QueueHandle_t integerQueue;
void setup() { #ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() {
/** /**
* Create a queue. * Create a queue.
* https://www.freertos.org/a00116.html * https://www.freertos.org/a00116.html
@ -53,7 +60,6 @@ void setup() {
NULL, NULL,
0, // Priority 0, // Priority
NULL ); NULL );
} }
void loop() {} void loop() {}
@ -79,7 +85,7 @@ void TaskAnalogRead(void *pvParameters)
*/ */
xQueueSend(integerQueue, &sensorValue, portMAX_DELAY); xQueueSend(integerQueue, &sensorValue, portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -94,11 +100,6 @@ void TaskSerial(void * pvParameters) {
// Init Arduino serial // Init Arduino serial
Serial.begin(9600); Serial.begin(9600);
// Wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
while (!Serial) {
vTaskDelay(1);
}
int valueFromQueue = 0; int valueFromQueue = 0;
for (;;) for (;;)
@ -122,13 +123,13 @@ void TaskBlink(void *pvParameters)
{ {
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) for (;;)
{ {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(LED_BUILTIN, LOW); digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
} }
} }

View File

@ -16,8 +16,25 @@
*/ */
SemaphoreHandle_t interruptSemaphore; SemaphoreHandle_t interruptSemaphore;
void setup() { // set interrupt pin
#ifdef BTN_BUILTIN
uint8_t int_pin = BTN_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t int_pin = P0_8;
#else
uint8_t int_pin = 2;
#endif
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 3;
#endif
void setup() {
// Create task for Arduino led // Create task for Arduino led
xTaskCreate(TaskLed, // Task function xTaskCreate(TaskLed, // Task function
"Led", // Task name "Led", // Task name
@ -33,10 +50,8 @@ void setup() {
interruptSemaphore = xSemaphoreCreateBinary(); interruptSemaphore = xSemaphoreCreateBinary();
if (interruptSemaphore != NULL) { if (interruptSemaphore != NULL) {
// Attach interrupt for Arduino digital pin // Attach interrupt for Arduino digital pin
attachInterrupt(digitalPinToInterrupt(BTN_BUILTIN), interruptHandler, RISING); attachInterrupt(digitalPinToInterrupt(int_pin), interruptHandler, RISING);
} }
} }
void loop() {} void loop() {}
@ -59,7 +74,7 @@ void TaskLed(void *pvParameters)
{ {
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) { for (;;) {
@ -68,7 +83,7 @@ void TaskLed(void *pvParameters)
* https://www.freertos.org/a00122.html * https://www.freertos.org/a00122.html
*/ */
if (xSemaphoreTake(interruptSemaphore, portMAX_DELAY) == pdPASS) { if (xSemaphoreTake(interruptSemaphore, portMAX_DELAY) == pdPASS) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); digitalWrite(blink_pin, !digitalRead(blink_pin));
} }
vTaskDelay(10); vTaskDelay(10);
} }

View File

@ -21,7 +21,6 @@ int task1Delay = 1250;
int task2Delay = 1000; int task2Delay = 1000;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
/** /**
@ -44,7 +43,6 @@ void setup() {
NULL); NULL);
xTaskCreate(TaskMutex, "Task2", 128, &task2Delay, 1, NULL); xTaskCreate(TaskMutex, "Task2", 128, &task2Delay, 1, NULL);
} }
void loop() {} void loop() {}

View File

@ -11,8 +11,16 @@
*/ */
TaskHandle_t taskNotificationHandler; TaskHandle_t taskNotificationHandler;
void setup() { // set interrupt pin
#ifdef BTN_BUILTIN
uint8_t int_pin = BTN_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t int_pin = P0_8;
#else
uint8_t int_pin = 2;
#endif
void setup() {
// Create task for FreeRTOS notification // Create task for FreeRTOS notification
xTaskCreate(TaskNotification, // Task function xTaskCreate(TaskNotification, // Task function
"Notification", // Task name "Notification", // Task name
@ -33,18 +41,15 @@ void TaskNotification(void *pvParameters)
{ {
(void) pvParameters; (void) pvParameters;
int digitalPin = BTN_BUILTIN;
Serial.begin(9600); Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(digitalPin), digitalPinInterruptHandler, RISING); attachInterrupt(digitalPinToInterrupt(int_pin), digitalPinInterruptHandler, RISING);
for (;;) { for (;;) {
if (ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) { if (ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) {
Serial.println("Notification received"); Serial.println("Notification received");
} }
} }
} }
@ -53,5 +58,4 @@ void digitalPinInterruptHandler() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(taskNotificationHandler, &xHigherPriorityTaskWoken); vTaskNotifyGiveFromISR(taskNotificationHandler, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
} }

View File

@ -15,6 +15,15 @@ struct Arduino{
int ReadValue[2]; int ReadValue[2];
}; };
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
//Function Declaration //Function Declaration
void Blink(void *pvParameters); void Blink(void *pvParameters);
void POT(void *pvParameters); void POT(void *pvParameters);
@ -36,8 +45,6 @@ structArrayQueue=xQueueCreate(10, //Queue length
sizeof(struct Arduino)); // Queue item size sizeof(struct Arduino)); // Queue item size
if(structArrayQueue!=NULL){ if(structArrayQueue!=NULL){
xTaskCreate(TaskBlink, // Task function xTaskCreate(TaskBlink, // Task function
"Blink", // Task name "Blink", // Task name
128, // Stack size 128, // Stack size
@ -72,15 +79,13 @@ void loop() {}
void TaskBlink(void *pvParameters){ void TaskBlink(void *pvParameters){
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN,OUTPUT); pinMode(blink_pin,OUTPUT);
digitalWrite(LED_BUILTIN,LOW);
for(;;) for(;;)
{ {
digitalWrite(LED_BUILTIN,HIGH); digitalWrite(blink_pin,HIGH);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
digitalWrite(LED_BUILTIN,LOW); digitalWrite(blink_pin,LOW);
vTaskDelay(250/portTICK_PERIOD_MS); vTaskDelay(250/portTICK_PERIOD_MS);
} }
} }
@ -109,7 +114,7 @@ void POT(void *pvParameters){
*/ */
xQueueSend(structArrayQueue,&currentVariable,portMAX_DELAY); xQueueSend(structArrayQueue,&currentVariable,portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -124,13 +129,7 @@ void TaskSerial(void *pvParameters){
// Init Arduino serial // Init Arduino serial
Serial.begin(9600); Serial.begin(9600);
// Wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
while (!Serial) {
vTaskDelay(1);
}
for (;;){ for (;;){
struct Arduino currentVariable; struct Arduino currentVariable;
/** /**

View File

@ -21,6 +21,15 @@ struct pinRead {
*/ */
QueueHandle_t structQueue; QueueHandle_t structQueue;
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() { void setup() {
/** /**
@ -57,7 +66,6 @@ void setup() {
NULL, NULL,
1, // Priority 1, // Priority
NULL); NULL);
} }
@ -95,7 +103,7 @@ void TaskAnalogReadPin0(void *pvParameters)
*/ */
xQueueSend(structQueue, &currentPinRead, portMAX_DELAY); xQueueSend(structQueue, &currentPinRead, portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -123,7 +131,7 @@ void TaskAnalogReadPin1(void *pvParameters)
*/ */
xQueueSend(structQueue, &currentPinRead, portMAX_DELAY); xQueueSend(structQueue, &currentPinRead, portMAX_DELAY);
// One tick delay (15ms) in between reads for stability // One tick delay (10ms) in between reads for stability
vTaskDelay(1); vTaskDelay(1);
} }
} }
@ -138,14 +146,8 @@ void TaskSerial(void * pvParameters) {
// Init Arduino serial // Init Arduino serial
Serial.begin(9600); Serial.begin(9600);
// Wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
while (!Serial) {
vTaskDelay(1);
}
for (;;) for (;;)
{ {
struct pinRead currentPinRead; struct pinRead currentPinRead;
/** /**
@ -169,13 +171,13 @@ void TaskBlink(void *pvParameters)
{ {
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) for (;;)
{ {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(LED_BUILTIN, LOW); digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
} }
} }

View File

@ -8,31 +8,36 @@ TaskHandle_t TaskSerial_Handler;
void TaskBlink( void *pvParameters ); void TaskBlink( void *pvParameters );
void TaskSerial(void* pvParameters); void TaskSerial(void* pvParameters);
// set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
// the setup function runs once when you press reset or power the board // the setup function runs once when you press reset or power the board
void setup() { void setup() {
// initialize serial communication at 9600 bits per second: // initialize serial communication at 9600 bits per second:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
}
// Now set up two tasks to run independently. // Now set up two tasks to run independently.
xTaskCreate( xTaskCreate(
TaskBlink TaskBlink,
, "Blink" // A name just for humans "Blink", // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater 128, // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters passed to the task function NULL, // Parameters passed to the task function
, 2 // Priority, with 2 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. 2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &TaskBlink_Handler );//Task handle &TaskBlink_Handler); // Task handle
xTaskCreate( xTaskCreate(
TaskSerial TaskSerial,
, "Serial" "Serial",
, 128 // Stack size 128, // Stack size
, NULL //Parameters passed to the task function NULL, // Parameters passed to the task function
, 1 // Priority 1, // Priority
, &TaskSerial_Handler ); //Task handle &TaskSerial_Handler); // Task handle
} }
@ -73,13 +78,12 @@ void TaskSerial(void* pvParameters){
void TaskBlink(void *pvParameters) // This is a task. void TaskBlink(void *pvParameters) // This is a task.
{ {
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) // A Task shall never return or exit. for (;;) // A Task shall never return or exit.
{ {
//Serial.println(11); digitalWrite(blink_pin, HIGH); // turn the pin on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW digitalWrite(blink_pin, LOW); // turn the pin off by making the voltage LOW
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
} }
} }

View File

@ -16,8 +16,16 @@ TaskHandle_t taskDeletedHandle;
TaskHandle_t taskBlockedHandle; TaskHandle_t taskBlockedHandle;
void setup() { // set led pin
#ifdef LED_BUILTIN
uint8_t blink_pin = LED_BUILTIN;
#elif defined(ARDUINO_ELSOMIK)
uint8_t blink_pin = P0_0;
#else
uint8_t blink_pin = 2;
#endif
void setup() {
/** /**
* Task creation * Task creation
*/ */
@ -48,7 +56,6 @@ void setup() {
NULL, NULL,
1, 1,
&taskBlockedHandle); &taskBlockedHandle);
} }
void loop() {} void loop() {}
@ -136,13 +143,13 @@ void TaskBlink(void *pvParameters)
{ {
(void) pvParameters; (void) pvParameters;
pinMode(LED_BUILTIN, OUTPUT); pinMode(blink_pin, OUTPUT);
for (;;) for (;;)
{ {
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(blink_pin, HIGH);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
digitalWrite(LED_BUILTIN, LOW); digitalWrite(blink_pin, LOW);
vTaskDelay( 250 / portTICK_PERIOD_MS ); vTaskDelay( 250 / portTICK_PERIOD_MS );
} }
} }