#include <STM32FreeRTOS.h>
#include "LiquidCrystal_I2C.h"
LiquidCrystal_I2C lcd(0x27, 20,4);
int sensorValue1,sensorValue2;
SemaphoreHandle_t adcSemaphore;
void TaskDigitalRead( void *pvParameters );
void TaskAnalogRead( void *pvParameters );
void setup()
{
adcSemaphore = xSemaphoreCreateBinary();
xTaskCreate(TaskDigitalRead,"DigitalRead",80,NULL,1,NULL);
xTaskCreate(TaskAnalogRead,"AnalogRead",80,NULL,1,NULL);
vTaskStartScheduler();
}
void loop()
{
}
void TaskDigitalRead( void *pvParameters ) // This is a Task.
{
while(1)
{
// read the input pin:
sensorValue1 = analogRead(A1);
sensorValue2 = analogRead(A0);
xSemaphoreGive( adcSemaphore );
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void TaskAnalogRead( void *pvParameters ) // This is a Task.
{
while(1)
{
if(xSemaphoreTake(adcSemaphore,portMAX_DELAY)==pdTRUE)
{
//int sensorValue1 = analogRead(A1);
//int sensorValue2 = analogRead(A0);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 2);
lcd.print("ADC1 : ");
lcd.print(sensorValue2);
lcd.setCursor(0, 3);
lcd.print("ADC2 : ");
lcd.print(sensorValue1);
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}