#include <LiquidCrystal_I2C.h> // Include the LiquidCrystal_I2C library
#define I2C_ADDR 0x27 // I2C address of the LCD
#define LCD_COLUMNS 16 // Number of columns in the LCD
#define LCD_LINES 2 // Number of lines in the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES); // Create an LCD object
void setup() {
// Initialize LCD and display "STARTING" message
lcd.init();
lcd.backlight();
lcd.print("STARTING");
// Set pin modes and test LEDs
for (int i = 0; i < 10; i++) {
pinMode(i, OUTPUT); // Set pin mode to OUTPUT
digitalWrite(i, HIGH); // Turn on LED for testing
}
delay(2000); // Wait for 2 seconds
lcd.clear(); // Clear the LCD screen
}
void loop() {
static int previousS = -1; // Variable to store the previous analog reading
int S = analogRead(A0); // Read analog input from the dial
// Check if the current analog reading is significantly different from the previous reading
if (abs(S - previousS) > 10) { // Adjust the threshold (10) according to your requirement
lcd.clear(); // Clear the LCD screen
lcd.print(S); // Print the analog input value on the LCD
previousS = S; // Update the previous analog reading
}
// Iterate over each LED pin and set its state based on the analog reading
for (int i = 0; i < 10; i++) {
if (S >= 102.3 * (i + 1)) {
digitalWrite(i, HIGH); // Turn on the LED
} else {
digitalWrite(i, LOW); // Turn off the LED
}
}
delay(10); // Delay for stability
}
// NEW CODE MADE BY ME WITH HELP FROM CHAT GTP
// https://chat.openai.com/share/f2fc0110-b115-4500-9061-46407b48b9ed