// Include required libraries
#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
// Define 20x4 LCD properties
LiquidCrystal_I2C lcd(0x27, 21, 20);
// Global variables
volatile bool displayUpdateNeeded = false;
void setup() {
// Start the LCD
lcd.init();
lcd.backlight();
// Core 1 settings
xTaskCreatePinnedToCore(
core1Task, /* Task function */
"core1Task", /* Name of the task */
10000, /* Stack size */
NULL, /* Task input parameter */
1, /* Priority */
NULL, /* Task handle */
1 /* Core on which the task will run */
);
}
void loop() {
if (displayUpdateNeeded) { // Check if display update is needed
// Generate a random float number
float randNum = getRandomFloat();
char displayStr[10]; // Assuming 10 characters for the LCD display
// Convert the float number to a string
dtostrf(randNum, 6, 2, displayStr); // Example: convert to string with 6 character total width and 2 decimal places
// Update the display with the string representation of the float
lcd.setCursor(0, 0);
lcd.print("Value: ");
lcd.setCursor(7, 0);
lcd.print(displayStr);
// Set the boolean back to 1 to indicate display update is completed
displayUpdateNeeded = false;
}
// Other operations in the main loop
}
// Core 1 task
void core1Task(void* param) {
// setupRandomSeed(); // Setup random seed if needed
while (1) {
if (!displayUpdateNeeded) {
// Set the boolean to indicate display update is needed
displayUpdateNeeded = true;
// Other operations in core 1
// Delay or other tasks
vTaskDelay(pdMS_TO_TICKS(1000)); // Delay for 1000ms (1 second)
}
}
}
// Function to generate a random float number
float getRandomFloat() {
return (float)random(0, 1000) / 100.0; // Example: generate a random float between 0 and 10.00
}