//Created by Barbu Vulc!
//Libraries needed for code:
#include <Arduino_FreeRTOS.h>
#include <LiquidCrystal.h>
//Create the 'lcd' object:
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//Define variables for photoresistor:
const int sensorMin = 0; //Sensor minimum...
const int sensorMax = 500; //Sensor maximum...
void setup() {
//LCD initialization:
lcd.begin(16, 2);
//Task initialization:
xTaskCreate(Task, "Photoresistor & LCD", 100, NULL, 0, NULL);
}
//The task for photoresistor & LCD:
static void Task(void* pvParameters) {
while (1) {
lcd.setCursor(0, 0);
//The photoresistor variable...
int ldr = analogRead(A0);
int range = map(ldr, sensorMin, sensorMax, 0, 3);
lcd.println(range); lcd.println("lux");
vTaskDelay(500 / portTICK_PERIOD_MS);
lcd.clear();
}
}
//We don't need to use 'loop' function here!
void loop() {}