#include <LiquidCrystal_I2C.h> // Include LiquidCrystal_I2C library for I2C LCD
const int ledPin = 13; // LED connected to pin 13
const int potPin = 0; // Potentiometer connected to analog pin 0
const int lcd_address = 0x27; // I2C address of your LCD (check datasheet)
LiquidCrystal_I2C lcd(lcd_address, 16, 2); // Initialize I2C LCD (address, columns, rows)
int potValue; // Variable to store potentiometer reading
int blinkRate; // Variable to store calculated blink rate (in Hz)
int blinkCount = 0; // Variable to count blinks
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
lcd.init(); // Initialize I2C LCD communication
lcd.backlight(); // Turn on LCD backlight (optional)
lcd.clear(); // Clear LCD display
}
void loop() {
potValue = analogRead(potPin); // Read analog value from potentiometer
// Map the potentiometer value to a blinking delay (e.g., 10ms to 1000ms)
int delayTime = map(potValue, 0, 1023, 10, 1000);
// Calculate blink rate (assuming delayTime represents milliseconds)
blinkRate = 1000 / delayTime;
digitalWrite(ledPin, HIGH); // Turn LED on
delay(delayTime); // Delay based on potentiometer value
digitalWrite(ledPin, LOW); // Turn LED off
delay(delayTime); // Delay based on potentiometer value
blinkCount++; // Increment blink count after each blink cycle
lcd.setCursor(0, 0); // Set cursor position on LCD (top-left)
lcd.print("Blink Rate:"); // Display "Blink Rate:" text
lcd.print(blinkRate); // Display calculated blink rate
lcd.print(" Hz"); // Display "Hz" unit
lcd.setCursor(0, 1); // Set cursor position on LCD (second row)
lcd.print("Blinks:"); // Display "Blinks:" text
lcd.print(blinkCount); // Display current blink count
}