#include <LiquidCrystal_I2C.h>
// Import ezButton library
#include <ezButton.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4);
int excellentCount = 0;
int goodCount = 0;
int badCount = 0;
// Declare all feedback variables and set in numbers
ezButton excellentButton(33);
ezButton goodButton(25);
ezButton badButton(19);
ezButton feedbackButton(18);
// Declare showFeeback as flag variable and set initial value to false
bool showFeedback = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// Set the debounce time for each button
excellentButton.setDebounceTime(25);
goodButton.setDebounceTime(25);
badButton.setDebounceTime(25);
feedbackButton.setDebounceTime(25);
// Initilized the LCD
initilizeLcd();
}
void loop() {
// Call loop method for each button
excellentButton.loop();
goodButton.loop();
badButton.loop();
feedbackButton.loop();
// Detect the button press and take action accordingly
if(!showFeedback){
if (excellentButton.isPressed()) {
Serial.println("Excellent");
excellentCount++;
}else if(goodButton.isPressed()){
Serial.println("Good");
goodCount++;
}else if(badButton.isPressed()){
Serial.println("Bad");
badCount++;
}else if(feedbackButton.isPressed()){
Serial.println("Show Feedback");
showFeedback = true;
lcd.clear();
delay(1000);
}
}else{
// Call the function showFeedbackResults()
showFeedbackResults();
}
delay(10);
}
void initilizeLcd(){
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Welcome to Star Fun!");
lcd.setCursor(0, 1);
lcd.print("We'd love to hear ");
lcd.setCursor(0, 2);
lcd.print("your feedback about");
lcd.setCursor(0,3);
lcd.print("our service!");
}
void showFeedbackResults(){
lcd.setCursor(0,0);
lcd.print("Excellent: ");
lcd.print(excellentCount);
lcd.setCursor(0,1);
lcd.print("Good: ");
lcd.print(goodCount);
lcd.setCursor(0,2);
lcd.print("Bad: ");
lcd.print(badCount);
delay(5000);
lcd.clear();
// Set the showFeedback to false
showFeedback = false;
initilizeLcd();
}