SE-TP2/code/LCDScreen.cpp

78 lines
2.1 KiB
C++

#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
enum LCDScreenState {
DISPLAY_DEFAULT_MESSAGE,
DISPLAY_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 = "Welcome!";
public:
LCDScreen(String default_message = ""){
if (default_message != ""){
this->default_message = default_message;
this->state = DISPLAY_DEFAULT_MESSAGE;
}
}
void init(){
lcd.init();
lcd.backlight();
this->display_message(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_message(String message){
if (this->state != DISPLAY_MESSAGE){
this->clear();
this->state = DISPLAY_MESSAGE;
}
lcd.setCursor(0, 0);
lcd.print(message);
}
void display_message_full(){
if (this->state != DISPLAY_PARKING_SPOTS_FULL){
this->clear();
this->state = DISPLAY_PARKING_SPOTS_FULL;
}
lcd.setCursor(0, 0);
lcd.print("Park is FULL.");
lcd.setCursor(0, 1);
lcd.print("Come back later.");
}
void display_message_SLOTS(int slots){
if (this->state != DISPLAY_PARKING_SPOTS){
this->clear();
this->state = DISPLAY_PARKING_SPOTS;
}
lcd.setCursor(0, 0);
lcd.print("Available slots: ");
lcd.setCursor(0, 1);
lcd.print(slots);
}
};