Data
Codigo que imprime um menu de dataunknown
c_cpp
2 years ago
2.3 kB
6
Indexable
#include<LiquidCrystal_I2C_Hangul.h> #include<Wire.h> #define BUTTON_PIN_1 16 // ESP32 pin GIOP16, which connected to button #define BUTTON_PIN_2 15 #define BUTTON_PIN_3 18 // variables will change: int button_state1; // the current state of button int last_button_state1; // the previous state of button int button_state2; // the current state of button int last_button_state2; int button_state3; // the current state of button int last_button_state3; int dia = 1; int mes = 1; int ano = 2023; LiquidCrystal_I2C_Hangul lcd(0x3F,16,2); //LCD 클래스 초기화 void setup() { Serial.begin(9600); // initialize serial pinMode(BUTTON_PIN_1, INPUT_PULLUP); // set ESP32 pin to input pull-up mode button_state1 = digitalRead(BUTTON_PIN_1); pinMode(BUTTON_PIN_2, INPUT_PULLUP); // set ESP32 pin to input pull-up mode button_state2 = digitalRead(BUTTON_PIN_2); pinMode(BUTTON_PIN_3, INPUT_PULLUP); // set ESP32 pin to input pull-up mode button_state3 = digitalRead(BUTTON_PIN_3); lcd.init(); lcd.backlight(); lcd.print("Data:"); atualizarDisplay(); } void loop() { last_button_state1 = button_state1; // save the last state button_state1 = digitalRead(BUTTON_PIN_1); // read new state last_button_state2 = button_state2; // save the last state button_state2 = digitalRead(BUTTON_PIN_2); last_button_state3 = button_state3; // save the last state button_state3 = digitalRead(BUTTON_PIN_3); if(last_button_state1 == HIGH && button_state1 == LOW){ Serial.println("The button 1 is pressed"); dia++; if(dia>31){ dia = 1; } atualizarDisplay(); delay(200); } if(last_button_state2 == HIGH && button_state2 == LOW){ Serial.println("The button 2 is pressed"); mes++; if(mes>12){ mes=1; } atualizarDisplay(); delay(200); } if(last_button_state3 == HIGH && button_state3 == LOW){ Serial.println("The button 3 is pressed"); ano++; atualizarDisplay(); delay(200); } } void atualizarDisplay(){ lcd.setCursor(0,1); if(dia<10){ lcd.print("0"); } lcd.print(dia); lcd.print("/"); if(mes<10){ lcd.print("0"); } lcd.print(mes); lcd.print("/"); lcd.print(ano); }
Editor is loading...