@@ -6,6 +6,13 @@ void TaskAnalogRead( void *pvParameters );
66
77// the setup function runs once when you press reset or power the board
88void setup () {
9+
10+ // initialize serial communication at 9600 bits per second:
11+ Serial.begin (9600 );
12+
13+ while (!Serial) {
14+ ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
15+ }
916
1017 // Now set up two tasks to run independently.
1118 xTaskCreate (
@@ -40,31 +47,61 @@ void TaskBlink(void *pvParameters) // This is a task.
4047{
4148 (void ) pvParameters;
4249
43- // initialize digital pin 13 as an output.
44- pinMode (13 , OUTPUT);
50+ /*
51+ Blink
52+ Turns on an LED on for one second, then off for one second, repeatedly.
53+
54+ Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO
55+ it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care
56+ of use the correct LED pin whatever is the board used.
57+
58+ The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute
59+ the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX.
60+ e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc.
61+
62+ If you want to know what pin the on-board LED is connected to on your Arduino model, check
63+ the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
64+
65+ This example code is in the public domain.
66+
67+ modified 8 May 2014
68+ by Scott Fitzgerald
69+
70+ modified 2 Sep 2016
71+ by Arturo Guadalupi
72+ */
73+
74+ // initialize digital LED_BUILTIN on pin 13 as an output.
75+ pinMode (LED_BUILTIN, OUTPUT);
4576
4677 for (;;) // A Task shall never return or exit.
4778 {
48- digitalWrite (13 , HIGH); // turn the LED on (HIGH is the voltage level)
79+ digitalWrite (LED_BUILTIN , HIGH); // turn the LED on (HIGH is the voltage level)
4980 vTaskDelay ( 1000 / portTICK_PERIOD_MS ); // wait for one second
50- digitalWrite (13 , LOW); // turn the LED off by making the voltage LOW
81+ digitalWrite (LED_BUILTIN , LOW); // turn the LED off by making the voltage LOW
5182 vTaskDelay ( 1000 / portTICK_PERIOD_MS ); // wait for one second
5283 }
5384}
5485
5586void TaskAnalogRead (void *pvParameters) // This is a task.
5687{
5788 (void ) pvParameters;
89+
90+ /*
91+ AnalogReadSerial
92+ Reads an analog input on pin 0, prints the result to the serial monitor.
93+ Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
94+ Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5895
59- // initialize serial communication at 9600 bits per second:
60- Serial. begin ( 9600 );
96+ This example code is in the public domain.
97+ */
6198
6299 for (;;)
63100 {
64101 // read the input on analog pin 0:
65102 int sensorValue = analogRead (A0);
66103 // print out the value you read:
67104 Serial.println (sensorValue);
68- vTaskDelay (1 ); // one tick delay (30ms ) in between reads for stability
105+ vTaskDelay (1 ); // one tick delay (15ms ) in between reads for stability
69106 }
70107}
0 commit comments