-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd_i2c.ino
111 lines (86 loc) · 2.19 KB
/
lcd_i2c.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 20, 4);
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET -3 * 3600
#define UTC_OFFSET_DST 0
#define BUTTON1_PIN 5 // Exemplo de pino para o botão 1
#define BUTTON2_PIN 15 // Exemplo de pino para o botão 2
bool backlightState = true;
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
LCD.setCursor(15, 1);
LCD.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
return;
}
LCD.setCursor(12, 0);
LCD.print(&timeinfo, "%H:%M:%S");
LCD.setCursor(10, 1);
LCD.print(&timeinfo, "%d/%m/%Y");
LCD.setCursor(13, 2);
LCD.print(&timeinfo, "%Z");
}
void inputControl() {
int button1State = digitalRead(BUTTON1_PIN);
int button2State = digitalRead(BUTTON2_PIN);
if (button1State == HIGH) {
//Serial.println("Botão 1 pressionado");
if (backlightState) {
LCD.noBacklight();
}
if (!backlightState) {
LCD.backlight();
}
backlightState = !backlightState;
}
if (button2State == HIGH) {
Serial.println("Botão 2 pressionado");
}
delay(100);
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON1_PIN, INPUT_PULLDOWN);
pinMode(BUTTON2_PIN, INPUT_PULLDOWN);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
WiFi.begin("4326853872", "B111013H", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
setenv("TZ", "America/Sao_Paulo", 1);
LCD.clear();
}
void loop() {
printLocalTime();
delay(250);
inputControl();
}