#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD, I2C address 0x27 is typical for 16x2 LCDs
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin connections for the flex sensors
const int flexPin1 = A0; // Flex sensor 1 connected to A0
const int flexPin2 = A1; // Flex sensor 2 connected to A1
// Variable to store the previous message
String previousMessage = "";
void setup() {
// Initialize the LCD
lcd.begin(16,2); // Initialize LCD with default dimensions
lcd.backlight(); // Turn on the backlight
// Initialize serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the analog values from both flex sensors
int flexValue1 = analogRead(flexPin1);
int flexValue2 = analogRead(flexPin2);
// Print the flex sensor values to the Serial Monitor (for debugging)
Serial.print("Flex Sensor 1: ");
Serial.print(flexValue1);
Serial.print(" Flex Sensor 2: ");
Serial.println(flexValue2);
// Compare the values of the two flex sensors
String currentMessage;
if (flexValue1 > flexValue2) {
currentMessage = "WATER"; // Message if Flex Sensor 1 is greater
} else if (flexValue1 == flexValue2){
currentMessage = "Move Your Fingers";
}
else {
currentMessage = "FOOD"; // Message if Flex Sensor 2 is greater or equal
}
// Only update the LCD if the message has changed
if (currentMessage != previousMessage) {
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print(currentMessage); // Display the new message
previousMessage = currentMessage; // Update previousMessage to the current one
}
delay(500); // Small delay between readings
}