#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <WiFi.h>
#include <HTTPClient.h>
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// WiFi credentials
const char* ssid = "Flare";
const char* password = "12345678";
void setup() {
// Initialize display
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Connecting...");
// Initialize WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
tft.setCursor(20, 160);
tft.println("Connecting to WiFi...");
}
// WiFi connected
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 120);
tft.println("WiFi connected");
// Make an HTTP request
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://www.google.com"); // Google homepage URL
int httpCode = http.GET(); // Send the request
if (httpCode > 0) { // Check for a successful response
String payload = http.getString(); // Get the response as a String
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(1);
// Display the first few lines of the response
tft.println("Google.com response:");
for (int i = 0; i < payload.length(); i += 20) {
if (i + 20 < payload.length()) {
tft.println(payload.substring(i, i + 20));
} else {
tft.println(payload.substring(i));
}
delay(100); // Slow down the text display for readability
}
} else {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.println("Failed to fetch!");
}
http.end(); // Close the connection
} else {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.println("WiFi not connected");
}
}
void loop() {
// nothing to do here
}