Replies: 1 comment
-
I'm not sure whether you read the background information but there are quite a few issues with your example, and it is clear that it won't run. The It is clear why your code is not working... void loop()
{
// Empty. Things are done in Tasks.
while(1)
{
}
} For reference, you've included a call to // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
// start FreeRTOS
vTaskStartScheduler(); Also for reference you're created two tasks that address the same LED hardware. Since they are configured to different delays it is likely you will get an odd flashing signal, rather than the nice even blink you expect. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
example have no vTaskStartScheduler(); function,
and
setup() function need code:
while(1)
{
noInterrupts();
count++;
interrupts();
}
project code:
#include <Arduino_FreeRTOS.h>
#include <LiquidCrystal.h>
volatile uint32_t count = 0;
const uint8_t LED_PIN = 7;
const uint8_t LED_SysState = 6;
// define two tasks for Blink & AnalogRead
void TaskSystemState(void *pvParameters);
void TaskBlink( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
Serial.println(F("init hardware serial port"));
Serial.println(F("system setup"));
// Now set up two tasks to run independently.
xTaskCreate(
TaskBlink
, (const portCHAR *)"Blink" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 1 being the highest, and 4 being the lowest.
, NULL );
xTaskCreate(
TaskSystemState
, (const portCHAR *)"SystemState" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 3 // Priority, with 1 being the highest, and 4 being the lowest.
, NULL );
xTaskCreate(
TaskAnalogRead
, (const portCHAR *) "AnalogRead"
, 128 // Stack size
, NULL
, 1 // Priority
, NULL );
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
// start FreeRTOS
vTaskStartScheduler();
// should never return
//Serial.println(F("Die"));
//while(1);
}
void loop()
{
// Empty. Things are done in Tasks.
while(1)
{
// must insure increment is atomic
// in case of context switch for print
noInterrupts();
count++;
interrupts();
}
}
/--------------------------------------------------/
/---------------------- Tasks ---------------------/
/--------------------------------------------------/
void TaskSystemState(void *pvParameters) // This is a task.
{
(void) pvParameters;
// initialize digital pin 13 as an output.
pinMode(LED_SysState, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(LED_SysState, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 200 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(LED_SysState, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 200 / portTICK_PERIOD_MS ); // wait for one second
}
}
void TaskAnalogRead(void *pvParameters) // This is a task.
{
(void) pvParameters;
// initialize serial communication at 9600 bits per second:
//Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
for (;;)
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
}
}
void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;
// initialize digital pin 13 as an output.
pinMode(LED_PIN, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 300 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 300 / portTICK_PERIOD_MS ); // wait for one second
}
}
Beta Was this translation helpful? Give feedback.
All reactions