Project for Driver Development and Resource Sharing Implementation
Name: Devkar Krishna
Group-A
1.Display 2ADC Values using semaphore
#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 )
{
while(1)
{
// read the input pin:
sensorValue1 = analogRead(A1);
sensorValue2 = analogRead(A0);
xSemaphoreGive( adcSemaphore );
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void TaskAnalogRead( void *pvParameters )
{
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 Value : ");
lcd.print(sensorValue2);
lcd.setCursor(0, 3);
lcd.print("ADC2 Value : ");
lcd.print(sensorValue1);
}
//Delay Generation vTaskDelay(pdMS_TO_TICKS(100));
}
}
