Skip to content

Commit f17a1d0

Browse files
committed
Added simple Blink & AnalogRead example.
1 parent 65dabbc commit f17a1d0

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <Arduino_FreeRTOS.h>
2+
3+
// define two tasks for Blink & AnalogRead
4+
void TaskBlink( void *pvParameters );
5+
void TaskAnalogRead( void *pvParameters );
6+
7+
// the setup function runs once when you press reset or power the board
8+
void setup() {
9+
10+
// Now set up two tasks to run independently.
11+
xTaskCreate(
12+
TaskBlink
13+
, (const portCHAR *)"Blink" // A name just for humans
14+
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
15+
, NULL
16+
, 2 // Priority, with 1 being the highest, and 4 being the lowest.
17+
, NULL );
18+
19+
xTaskCreate(
20+
TaskAnalogRead
21+
, (const portCHAR *) "AnalogRead"
22+
, 128 // Stack size
23+
, NULL
24+
, 1 // Priority
25+
, NULL );
26+
27+
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
28+
}
29+
30+
void loop()
31+
{
32+
// Empty. Things are done in Tasks.
33+
}
34+
35+
/*--------------------------------------------------*/
36+
/*---------------------- Tasks ---------------------*/
37+
/*--------------------------------------------------*/
38+
39+
void TaskBlink(void *pvParameters) // This is a task.
40+
{
41+
(void) pvParameters;
42+
43+
// initialize digital pin 13 as an output.
44+
pinMode(13, OUTPUT);
45+
46+
for (;;) // A Task shall never return or exit.
47+
{
48+
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
49+
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
50+
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
51+
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
52+
}
53+
}
54+
55+
void TaskAnalogRead(void *pvParameters) // This is a task.
56+
{
57+
(void) pvParameters;
58+
59+
// initialize serial communication at 9600 bits per second:
60+
Serial.begin(9600);
61+
62+
for (;;)
63+
{
64+
// read the input on analog pin 0:
65+
int sensorValue = analogRead(A0);
66+
// print out the value you read:
67+
Serial.println(sensorValue);
68+
vTaskDelay(1); // one tick delay (30ms) in between reads for stability
69+
}
70+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=FreeRTOS
2-
version=8.2.3-8
2+
version=8.2.3-9
33
author=Richard Berry <[email protected]>
44
maintainer=Phillip Stevens <[email protected]>
55
sentence=Real Time Operating System implemented for AVR (Uno, Leonardo, Mega).

0 commit comments

Comments
 (0)