/*
SparkFun Inventor’s Kit
Circuit 4B - Temperature Sensor
The LCD will display readings from a temperature sensor in degrees Celsius and Fahrenheit.
This sketch was written by SparkFun Electronics, with lots of help from the Arduino community.
This code is completely free for any use.
View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-experiment-guide---v40
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
*/
//#include <LiquidCrystal_I2C.h>
//#include <LiquidCrystal.h> //the liquid crystal library contains commands for printing to the display
//LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
//LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 20 column and 4 rows
#include <Arduino_FreeRTOS.h>
#include <queue.h>
#include <LiquidCrystal_I2C.h> //the liquid crystal library contains commands for printing to the display
LiquidCrystal_I2C lcd(0x27, 20,4); // tell the RedBoard what pins are connected to the display
TaskHandle_t config_handle;
struct readings{
float voltage = 0; //the voltage measured from the TMP36
float degreesC = 0; //the temperature in Celsius, calculated from the voltage
float degreesF = 0;
};
QueueHandle_t my_queue;
void setup() {
lcd.begin(16, 2); //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high
lcd.clear(); //clear the display
xTaskCreate(print_task, "print task", 128, NULL, 3, &config_handle );
xTaskCreate(clean_up, "clean task", 128, NULL, 2, NULL );
my_queue=xQueueCreate(1, sizeof(struct readings));
xTaskCreate(read_data,"read sensors",128,NULL, 0,NULL);
xTaskCreate(display,"display",128,NULL, 0,NULL);
}
void loop()
{
// Empty. Things are done in Tasks.
}
void print_task(void *pvParameters)
{
while(1){
lcd.clear(); //clear the LCD
lcd.setCursor(0, 0); //set the cursor to the top left position
lcd.print("Degrees C: \n"); //print a label for the data
lcd.print("Degrees F"); //print the degrees Celsius
vTaskDelay( 1000 / portTICK_PERIOD_MS );
}
}
void clean_up(void *pvParameters)
{
lcd.println("Deleted ");
vTaskDelete(config_handle);
while(1){
vTaskDelay( 1000 / portTICK_PERIOD_MS );
}
}
void read_data(void *pvParameters){
struct readings x;
for(;;)
{
x.voltage = analogRead(A0) * 0.004882813;;
x.degreesC = (x.voltage - 0.5) * 100.0;
x.degreesF = x.degreesC * (9.0 / 5.0) + 32.0;
xQueueSend(my_queue,&x,portMAX_DELAY);
vTaskDelay(100);
}
}
void display(void *pvParameters){
struct readings x;
for(;;)
{
if(xQueueReceive(my_queue,&x,portMAX_DELAY) == pdPASS ){
lcd.clear(); //clear the LCD
lcd.setCursor(0, 0); //set the cursor to the top left position
lcd.print("Degrees C: "); //print a label for the data
lcd.print(x.degreesC); //print the degrees Celsius
lcd.setCursor(0, 1); //set the cursor to the lower left position
lcd.print("Degrees F: "); //Print a label for the data
lcd.print(x.degreesF); //print the degrees Fahrenheit
vTaskDelay( 5000 / portTICK_PERIOD_MS );
}
}
}