/* Basic Multi Threading Arduino Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
// Please read file README.md in the folder containing this example.
#if CONFIG_FREERTOS_UNICORE
#define TASK_RUNNING_CORE 0
#else
#define TASK_RUNNING_CORE 1
#endif
#define ANALOG_INPUT_PIN A0
#ifndef LED_BUILTIN
#define LED_BUILTIN 13 // Specify the on which is your LED
#define LED_BUILTIN_2 12 // Specify the on which is your LED
#define BUTTON_1 34
#endif
// Define two tasks for Blink & AnalogRead.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void TaskBlink(void *pvParameters);
void TaskLCD(void *pvParameters);
// void TaskBlink2(void *pvParameters);
TaskHandle_t analog_read_task_handle; // You can (don't have to) use this to be able to manipulate a task from somewhere else.
// The setup function runs once when you press reset or power on the board.
void setup() {
// Initialize serial communication at 115200 bits per second:
Serial.begin(115200);
// lcd.begin();
// Set up two tasks to run independently.
uint32_t blink_delay = 1000; // Delay between changing state on LED pin
xTaskCreate(
TaskBlink, "Task Blink" // A name just for humans
,
2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
,
NULL
,
2 // Priority
,
NULL // Task handle is not used here - simply pass NULL
);
xTaskCreate(
TaskLCD, "TaskLCD" // A name just for humans
,
2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
,
NULL
,
2 // Priority
,
NULL // Task handle is not used here - simply pass NULL
);
// xTaskCreate(
// TaskBlink2, "Task Blink 2" // A name just for humans
// ,
// 2048 // The stack size can be checked by calling `uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);`
// ,
// NULL
// ,
// 2 // Priority
// ,
// NULL // Task handle is not used here - simply pass NULL
// );
// This variant of task creation can also specify on which core it will be run (only relevant for multi-core ESPs)
Serial.printf("Basic Multi Threading Arduino Example\n");
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}
void loop() {
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskBlink(void *pvParameters) { // This is a task.
pinMode(LED_BUILTIN, OUTPUT);
for (;;) {
//Serial.println("baca lur"); // A Task shall never return or exit.
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
}
void TaskLCD(void *pvParameters){
//lcd.begin();
lcd.init();
lcd.backlight();
for(;;){
lcd.setCursor(0, 0);
for (char c = 'A'; c <= 'Z'; c++) {
lcd.print(c);
delay(200);
if (c == 'P') {
lcd.setCursor(0, 1); // Baris kedua
}
}
// Serial.println("kebaca ga ni?");
// lcd.setCursor(4,0); //kiri : kolom, kanan : baris
// lcd.print("Aku");
// //delay(500);
// lcd.setCursor(9,0);
// lcd.print("Adit");
// //delay(500);
// lcd.setCursor(6,1);
// lcd.print("hehe");
}
}
// void TaskBlink2(void *pvParameters) {
// uint32_t blink_delay = *((uint32_t *)pvParameters);
// pinMode(LED_BUILTIN_2, OUTPUT);
// for (;;) {
// digitalWrite(LED_BUILTIN_2, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(100);
// digitalWrite(LED_BUILTIN_2, LOW); // turn the LED off by making the voltage LOW
// delay(100);
// }
//}