#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include the LiquidCrystal I2C library
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define pins for buttons and LEDs
const int positiveButtonPin = 2;
const int negativeButtonPin = 3;
const int greenLedPin = 4;
const int redLedPin = 5;
// Variables to store feedback counts
int positiveCount = 0;
int negativeCount = 0;
void setup() {
Wire.begin(); // Initialize I2C communication
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Set button pins as inputs
pinMode(positiveButtonPin, INPUT_PULLUP);
pinMode(negativeButtonPin, INPUT_PULLUP);
// Set LED pins as outputs
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
// Initialize LEDs to OFF state
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, LOW);
Serial.begin(9600);
}
void loop() {
// Check if positive feedback button is pressed
if (digitalRead(positiveButtonPin) == LOW) {
// Increment positive feedback count
positiveCount++;
// Blink green LED to indicate positive feedback
digitalWrite(greenLedPin, HIGH);
delay(500);
digitalWrite(greenLedPin, LOW);
delay(500);
}
// Check if negative feedback button is pressed
if (digitalRead(negativeButtonPin) == LOW) {
// Increment negative feedback count
negativeCount++;
// Blink red LED to indicate negative feedback
digitalWrite(redLedPin, HIGH);
delay(500);
digitalWrite(redLedPin, LOW);
delay(500);
}
if (millis()% 5000 == 0){
Serial.println("========================================================================");
Serial.print("Good Feedback count: ");
Serial.println(positiveCount);
Serial.print("Bad Feedback count: ");
Serial.println(negativeCount);
Serial.println("========================================================================");
}
// Clear the LCD display
lcd.setCursor(0, 0); // Set cursor to first row
lcd.print("Good:"); // Print cleanliness status
lcd.print(positiveCount);
// Clear the LCD display
lcd.setCursor(0, 1); // Set cursor to first row
lcd.print("Bad:"); // Print cleanliness status
lcd.print(negativeCount);
delay(100);
// Print feedback counts to serial monitor (optional)
//Serial.print("Positive count: ");
//Serial.println(positiveCount);
//Serial.print("Negative count: ");
//Serial.println(negativeCount);
// Delay to debounce buttons
// delay(100
}