#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Create an LCD object with the pin connections
int stressLevel = 50; // Initial stress level
void setup() {
lcd.begin(16, 2); // Initialize the LCD
lcd.print("Stress Level "); // Display the initial text
lcd.setCursor(15, 0); // Position the cursor for the percentage
lcd.print("%");
lcd.setCursor(13, 0); // Position the cursor for the value
lcd.print(stressLevel);
pinMode(8, INPUT_PULLUP); // Button for increasing stress
pinMode(9, INPUT_PULLUP); // Button for decreasing stress
}
void loop() {
if (digitalRead(8) == LOW) { // Check if the increase button is pressed
delay(200); // Debounce delay
stressLevel = min(100, stressLevel + 5); // Increase stress level (capped at 100%)
updateLCD();
}
if (digitalRead(9) == LOW) { // Check if the decrease button is pressed
delay(200); // Debounce delay
stressLevel = max(0, stressLevel - 5); // Decrease stress level (minimum 0%)
updateLCD();
}
}
void updateLCD() {
lcd.setCursor(13, 0);
lcd.print(" "); // Clear the old value
lcd.setCursor(13, 0);
lcd.print(stressLevel); // Display the new stress level
}