// the setup function runs once when you press reset or power the board voidsetup() { // initialize serial communication at 115200 bits per second: USBSerial.begin(115200); // Now set up two tasks to run independently. xTaskCreatePinnedToCore( TaskBlink , "TaskBlink"// A name just for humans , 1024// This stack size can be checked & adjusted by reading the Stack Highwater , NULL , 2// Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. , NULL , ARDUINO_RUNNING_CORE);
voidTaskBlink(void *pvParameters)// This is a task. { (void) pvParameters;
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. If you want to know what pin the on-board LED is connected to on your ESP32 model, check the Technical Specs of your board. */
// initialize digital LED_BUILTIN on pin 13 as an output. pinMode(45, OUTPUT);
for (;;) // A Task shall never return or exit. { digitalWrite(45, HIGH); // turn the LED on (HIGH is the voltage level) vTaskDelay(100); // one tick delay (15ms) in between reads for stability digitalWrite(45, LOW); // turn the LED off by making the voltage LOW vTaskDelay(100); // one tick delay (15ms) in between reads for stability } }
voidTaskAnalogReadA3(void *pvParameters)// This is a task. { (void) pvParameters; /* AnalogReadSerial Reads an analog input on pin A3, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A3, and the outside pins to +5V and ground. This example code is in the public domain. */
for (;;) { // read the input on analog pin A3: int sensorValueA3 = analogRead(A3); // print out the value you read: USBSerial.print("A3->"); USBSerial.println(sensorValueA3); vTaskDelay(100); // one tick delay (15ms) in between reads for stability } }
xTaskCreate( xTaskOne, /* Task function. */ "TaskOne", /* String with name of task. */ 4096, /* Stack size in bytes. */ NULL, /* Parameter passed as input of the task */ 1, /* Priority of the task.(configMAX_PRIORITIES - 1 being the highest, and 0 being the lowest.) */ NULL); /* Task handle. */
xTaskCreate( xTaskTwo, /* Task function. */ "TaskTwo", /* String with name of task. */ 4096, /* Stack size in bytes. */ NULL, /* Parameter passed as input of the task */ 2, /* Priority of the task.(configMAX_PRIORITIES - 1 being the highest, and 0 being the lowest.) */ NULL); /* Task handle. */