#include #include enum LCDScreenState { DISPLAY_DEFAULT_MESSAGE = 0, DISPLAY_TEMPERATURE, DISPLAY_PARKING_SPOTS, CONFIGURATION_SCREEN }; class LCDScreen { private: LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,20,4); LCDScreenState current_state = 0; String default_message = "Bem vindo!"; public: LCDScreenState ordered_states[3] = { DISPLAY_DEFAULT_MESSAGE, DISPLAY_TEMPERATURE, DISPLAY_PARKING_SPOTS }; 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){ lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(temp,1); lcd.print(" C "); } void display_default_message(){ lcd.setCursor(0, 0); lcd.print(this->default_message); } void display_parking_spots(int total_spots, int occupied_spots){ int free_spots = total_spots - occupied_spots; lcd.setCursor(0, 0); lcd.print("Occupied: "); lcd.print(occupied_spots); lcd.print(" / "); lcd.print(total_spots); lcd.setCursor(0, 1); lcd.print("Free: "); lcd.print(free_spots); } void display_configuration_screen(int total_spots){ if (this->current_state != CONFIGURATION_SCREEN){ this->current_state = CONFIGURATION_SCREEN; this->clear(); lcd.setCursor(0, 0); lcd.print("Conf. Mode"); } lcd.setCursor(0, 1); lcd.print("Total Spots = "); if (total_spots < 10){ lcd.print("0"); lcd.print(total_spots); }else { lcd.print(total_spots); } } LCDScreenState get_next_state(){ if (this->current_state == 2){ return this->ordered_states[0]; } return this->ordered_states[this->current_state + 1]; } LCDScreenState get_previous_state(){ if (this->current_state == 0){ return this->ordered_states[2]; } return this->ordered_states[this->current_state - 1]; } void set_state(LCDScreenState state){ this->clear(); this->current_state = state; } void display(float temperature_in_c, int total_spots, int occupied_spots){ switch(this->current_state){ case DISPLAY_DEFAULT_MESSAGE: this->display_default_message(); break; case DISPLAY_TEMPERATURE: this->display_temperature(temperature_in_c); break; case DISPLAY_PARKING_SPOTS: this->display_parking_spots(total_spots, occupied_spots); break; } } };