-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_ar.ino
86 lines (73 loc) · 2.32 KB
/
project_ar.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
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ArduinoJson.h>
#define SCREEN_WIDTH 128 // OLED display width
#define SCREEN_HEIGHT 64 // OLED display height
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Declaration for SSD1306
const char* ssid = "Xeift";
const char* password = "13241324";
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
// Connect to Wi-Fi
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Connecting to: ");
display.println(ssid);
display.display();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
display.print(".");
display.display();
}
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Connected, ");
display.println("IP: ");
display.println(WiFi.localIP());
display.print("Ready to display =w=");
display.display();
}
void loop() {
String btcPrice = sendGetRequestAndParsePrice("BTC");
delay(3000);
String ethPrice = sendGetRequestAndParsePrice("ETH");
delay(3000);
String bnbPrice = sendGetRequestAndParsePrice("BNB");
delay(3000);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.print("BTC:" + btcPrice + "\n");
display.print("ETH:" + ethPrice + "\n");
display.print("BNB:" + bnbPrice + "\n");
display.display();
}
String sendGetRequestAndParsePrice(String tokenName) {
HTTPClient http;
http.begin("https://min-api.cryptocompare.com/data/generateAvg?fsym=" + tokenName + "&tsym=USDT&e=binance");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
http.end();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
double price = doc["RAW"]["PRICE"];
int roundedPrice = (int) round(price);
return String(roundedPrice);
}
else {
http.end();
return "-1.0";
}
}