#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
const char* ssid = "Wokwi-GUEST"; //Your SSID name
const char* password = ""; //Wifi Password
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
const String url = "https://api.kyroskoh.xyz/valorant/v1/mmr/NA/IG%20NetTurner505/AMnky";
String getMMR() {
HTTPClient http;
http.useHTTP10(true);
http.begin(url);
int httpCode = http.GET();
String response;
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
response = http.getString();
}
} else {
Serial.printf("HTTP GET request failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
return response;
}
void displayMMR() {
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(5);
//tft.println("\nObteniendo Rango...");
String mmrText = getMMR();
tft.setTextColor(ILI9341_GREEN);
tft.println(mmrText);
// Determine the color based on the MMR text
uint16_t circleColor = ILI9341_BLACK; // Default color is black
if (mmrText.indexOf("Iron") != -1) {
circleColor = ILI9341_DARKGREY;
tft.setTextColor(ILI9341_DARKGREY);
} else if (mmrText.indexOf("Silver") != -1) {
circleColor = ILI9341_LIGHTGREY;
tft.setTextColor(ILI9341_LIGHTGREY); // Gray for Silver
} else if (mmrText.indexOf("Gold") != -1) {
circleColor = ILI9341_YELLOW; // Yellow for Gold
tft.setTextColor(ILI9341_YELLOW);
} else if (mmrText.indexOf("Platinum") != -1) {
circleColor = ILI9341_CYAN; // Emerald green for Platinum
tft.setTextColor(ILI9341_CYAN);
} else if (mmrText.indexOf("Diamond") != -1) {
circleColor = ILI9341_PURPLE; // Purple for Diamond
tft.setTextColor(ILI9341_PURPLE);
} else if (mmrText.indexOf("Ascendant") != -1) {
circleColor = ILI9341_DARKCYAN; // Red for Immortal
tft.setTextColor(ILI9341_DARKCYAN);
} else if (mmrText.indexOf("Immortal") != -1) {
circleColor = ILI9341_RED;
tft.setTextColor(ILI9341_RED);
// Red for Immortal
} else if (mmrText.indexOf("Radiant") != -1) {
circleColor = ILI9341_CYAN;
tft.setTextColor(ILI9341_OLIVE);
// Cyan for Radiant
}
// Draw a circle with the determined color
tft.fillCircle(120, 160, 40, circleColor);
}
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
WiFi.begin(ssid, password, 6);
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
//tft.print("Connecting to WiFi");
/*
while (WiFi.status() != WL_CONNECTED) {
delay(100);
tft.print("Wifi Connected!");
}
*/
//tft.print("\nOK! IP=");
//tft.println(WiFi.localIP());
displayMMR();
}
void loop() {
if (digitalRead(BTN_PIN) == LOW) {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
displayMMR();
}
delay(100);
}