#include <LiquidCrystal_I2C.h>
// Set the LCD address, number of columns and rows
#define LCD_address 0x27
#define LCD_columns 16
#define LCD_rows 2
// Define the LED pin
#define LED_PIN 14
// Create an instance of the LiquidCrystal_I2C class
LiquidCrystal_I2C lcd(LCD_address, LCD_columns, LCD_rows);
// Define custom characters
byte customChar[] = {
0x1F,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x1F
};
byte customChar1[] = {
0x07,
0x04,
0x07,
0x04,
0x07,
0x04,
0x04,
0x0E
};
byte customChar2[] = {
0x11,
0x11,
0x11,
0x1F,
0x11,
0x11,
0x11,
0x11
};
int cursorPos = 0; // Start position of the cursor
bool ledState = false; // LED state for blinking
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(LED_PIN, OUTPUT); // Set the LED pin as output
// Create custom characters in the LCD's memory
lcd.createChar(0, customChar);
lcd.createChar(1, customChar1);
lcd.createChar(2, customChar2);
// Set up the display content
lcd.clear();
lcd.setCursor(0, 0);
lcd.write(0); // Display the first custom character
lcd.setCursor(8, 0); // Move cursor to the second column of the first row
lcd.write(1); // Display the second custom character
lcd.setCursor(15, 0); // Move cursor to first column of the second row
lcd.write(2); // Display the third custom character
lcd.setCursor(0, 1);
lcd.print("...........****"); // Temperature "gauge"
}
void loop() {
// Move cursor to the current position on the second row
lcd.setCursor(cursorPos, 1);
lcd.print(">"); // Display the "reading" cursor
delay(250); // Delay for the cursor movement
// Check if cursor reaches the "*" position
if (cursorPos >= 11) { // '*' starts at position 11
digitalWrite(LED_PIN, ledState); // Blink the LED
ledState = !ledState; // Toggle LED state
delay(500); // LED blink delay
} else {
digitalWrite(LED_PIN, LOW); // Ensure LED is off if cursor is not at '*'
}
// Clear the cursor symbol before moving to the next position
lcd.setCursor(cursorPos, 1);
lcd.print("."); // Restore original character
// Move cursor to the next position
cursorPos++;
if (cursorPos > 15) { // Reset cursor to the start after reaching the end
cursorPos = 0;
}
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4