-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticker_v2
137 lines (115 loc) · 3.47 KB
/
ticker_v2
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "SSID";
const char* password = "SSIDPassword";
void setup() {
M5.begin();
M5.Lcd.setTextColor(TFT_GREEN);
M5.Lcd.setTextSize(2);
M5.Lcd.fillScreen(TFT_BLACK);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
String getBitcoinPrice() {
HTTPClient http;
http.begin("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
JsonObject bitcoin = doc["bitcoin"];
double price = bitcoin["usd"];
http.end();
return String(price, 2);
} else {
http.end();
return "N/A";
}
}
String getEthereumPrice() {
HTTPClient http;
http.begin("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
JsonObject ethereum = doc["ethereum"];
double price = ethereum["usd"];
http.end();
return String(price, 2);
} else {
http.end();
return "N/A";
}
}
String getBitcoinPriceChange() {
HTTPClient http;
http.begin("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
JsonObject bitcoin = doc["bitcoin"];
double change = bitcoin["usd_24h_change"];
http.end();
return String(change, 2) + "%";
} else {
http.end();
return "N/A";
}
}
String getEthereumPriceChange() {
HTTPClient http;
http.begin("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd&include_24hr_change=true");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
JsonObject ethereum = doc["ethereum"];
double change = ethereum["usd_24h_change"];
http.end();
return String(change, 2) + "%";
} else {
http.end();
return "N/A";
}
}
void updatePriceLabels() {
String bitcoinPrice = getBitcoinPrice();
String bitcoinChange = getBitcoinPriceChange();
String ethereumPrice = getEthereumPrice();
String ethereumChange = getEthereumPriceChange();
M5.Lcd.fillScreen(TFT_BLACK);
int lineHeight = 30;
int startY = (M5.Lcd.height() - (lineHeight * 7)) / 2-20;
M5.Lcd.setTextColor(TFT_GREEN);
M5.Lcd.setTextSize(3);
// Affichage des prix du Bitcoin
M5.Lcd.setCursor(10, startY + lineHeight);
M5.Lcd.print("Bitcoin:");
M5.Lcd.setCursor(10, startY + lineHeight * 2);
M5.Lcd.print(bitcoinPrice + " USD");
M5.Lcd.setCursor(10, startY + lineHeight * 3);
M5.Lcd.print("Change: " + bitcoinChange);
// Affichage des prix de l'Ethereum
M5.Lcd.setCursor(10, startY + lineHeight * 5);
M5.Lcd.print("Ethereum:");
M5.Lcd.setCursor(10, startY + lineHeight * 6);
M5.Lcd.print(ethereumPrice + " USD");
M5.Lcd.setCursor(10, startY + lineHeight * 7);
M5.Lcd.print("Change: " + ethereumChange);
}
void loop() {
updatePriceLabels();
delay(30000);
}