SE-TP2/code/LCDScreen.cpp

69 lines
1.8 KiB
C++

#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
enum LCDScreenState {
DISPLAY_DEFAULT_MESSAGE,
DISPLAY_TEMPERATURE,
DISPLAY_PARKING_SPOTS_FULL,
DISPLAY_PARKING_SPOTS
};
class LCDScreen {
private:
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,20,4);
LCDScreenState state;
String default_message = "Bem vindo!";
public:
LCDScreen(String default_message = ""){
if (default_message != ""){
this->default_message = default_message;
}
}
void init(){
lcd.init();
lcd.backlight();
this->display_default_message();
}
void clear(){
lcd.clear();
}
void display_temperature(float temp){
if (this->state != DISPLAY_TEMPERATURE){
this->clear();
this->state = DISPLAY_TEMPERATURE;
}
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp,1);
lcd.print(" C ");
}
void display_default_message(){
if (this->state != DISPLAY_DEFAULT_MESSAGE){
this->clear();
this->state = DISPLAY_DEFAULT_MESSAGE;
}
lcd.setCursor(0, 0);
lcd.print(this->default_message);
}
void display_message_full(){
this->state = DISPLAY_PARKING_SPOTS_FULL;
lcd.setCursor(0, 0);
this->clear();
lcd.print("Parking Lot is FULL.\nPlease come back later.\n");
}
void display_message(int slots){
this->state = DISPLAY_PARKING_SPOTS;
lcd.setCursor(0, 0);
this->clear();
lcd.print("Available slots: ");
lcd.print(slots); lcd.print('\n');
}
};