-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker_v1
78 lines (69 loc) · 1.84 KB
/
ticker_v1
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
#include <M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "SSID";
const char* password = "SSID Password";
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";
}
}
void updatePriceLabels() {
String bitcoinPrice = getBitcoinPrice();
String ethereumPrice = getEthereumPrice();
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setCursor(10, 60);
M5.Lcd.print("Bitcoin:");
M5.Lcd.setCursor(10, 90);
M5.Lcd.print(bitcoinPrice + " USD");
M5.Lcd.setCursor(10, 150);
M5.Lcd.print("Ethereum:");
M5.Lcd.setCursor(10, 180);
M5.Lcd.print(ethereumPrice + " USD");
}
void loop() {
updatePriceLabels();
delay(10000);
}