#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
HTTPClient http;
const String url = "http://api.coindesk.com/v1/bpi/currentprice/BTC.json";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S3!");
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Bitcoin Price");
WiFi.begin("Wokwi-GUEST", "");
}
void loop() {
// put your main code here, to run repeatedly:
delay(5000); // this speeds up the simulation
if (WiFi.status() == 3) {
http.begin(url);
int httpCode = http.GET();
if (httpCode == 200) {
StaticJsonDocument<768> doc;
DeserializationError error = deserializeJson(doc, http.getString());
if (error) {
Serial.print(F("deserializeJson failed: "));
Serial.println(error.f_str());
delay(2500);
return;
}
String BTCUSDPrice = doc["bpi"]["USD"]["rate_float"].as<String>();
LCD.setCursor(0, 1);
LCD.print("$");
LCD.setCursor(2, 1);
LCD.print(BTCUSDPrice);
Serial.println(BTCUSDPrice);
}
http.end();
}
}