#include <WiFi.h>
#include <HTTPClient.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "time.h"
#define TFT_CS 10
#define TFT_DC 12
#define TFT_RST 11
#define TFT_MOSI 13
#define TFT_CLK 14
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
struct Sinav { char ad[15]; int g; int a; };
Sinav sinavlar[] = {
{"Turkce", 30, 3}, {"Fen Bil.", 31, 3}, {"Ingilizce", 1, 4},
{"Sosyal Bil.", 2, 4}, {"Matematik", 3, 4}, {"Din Kult.", 6, 4}
};
const char* program[5][7] = {
{"Turkce", "Turkce", "Mat", "Mat", "Fen", "Sosyal", "Ing"},
{"Fen", "Fen", "Turkce", "Sosyal", "Sosyal", "Din", "Din"},
{"Mat", "Mat", "Ing", "Ing", "Turkce", "Gorsel", "Muzik"},
{"Beden", "Beden", "Fen", "Fen", "Mat", "Turkce", "Turkce"},
{"Rehber", "Sosyal", "Ing", "Ing", "TekTas", "TekTas", "Bilisim"}
};
String safDerece = "--";
unsigned long sonHavaGuncelleme = 0;
int sonSaniye = -1;
void havaDurumuAl() {
if(WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://wttr.in/Safranbolu?format=%t");
int httpCode = http.GET();
if(httpCode > 0) {
String hamVeri = http.getString();
safDerece = "";
for(int j=0; j<hamVeri.length(); j++){
if(isdigit(hamVeri[j])) safDerece += hamVeri[j];
}
}
http.end();
}
}
void setup() {
tft.begin();
tft.setRotation(0);
tft.fillScreen(ILI9341_BLACK);
WiFi.begin("Wokwi-GUEST", "");
while (WiFi.status() != WL_CONNECTED) delay(100);
configTime(10800, 0, "pool.ntp.org");
havaDurumuAl();
tft.fillScreen(ILI9341_BLACK);
// EKRANI İLK AÇILIŞTA TAM DOLDUR
struct tm ti;
while(!getLocalTime(&ti)) delay(10);
sabitleriCiz();
dinamikIcerikCiz(&ti);
}
void loop() {
struct tm ti;
if(!getLocalTime(&ti)) return;
if (ti.tm_sec != sonSaniye) {
sonSaniye = ti.tm_sec;
saatGuncelle(&ti);
// Saat gece yarısı olduğunda veya her saat başı listeleri tazele
if (ti.tm_min == 0 && ti.tm_sec == 0) dinamikIcerikCiz(&ti);
}
if (millis() - sonHavaGuncelleme > 1800000) {
havaDurumuAl();
sonHavaGuncelleme = millis();
sabitleriCiz();
}
}
void saatGuncelle(struct tm *ti) {
tft.fillRect(5, 5, 120, 25, 0x000F);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.printf("%02d:%02d:%02d", ti->tm_hour, ti->tm_min, ti->tm_sec);
}
void sabitleriCiz() {
tft.fillRect(0, 0, 240, 35, 0x000F);
tft.setCursor(170, 10);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print(safDerece); tft.print(" C");
// Necmettin - Gözlük çizgisi olmadan
int nx = 195, ny = 280;
tft.fillCircle(nx, ny, 25, ILI9341_YELLOW);
tft.fillCircle(nx-9, ny-6, 4, ILI9341_BLACK);
tft.fillCircle(nx+9, ny-6, 4, ILI9341_BLACK);
tft.drawCircle(nx, ny+5, 10, ILI9341_BLACK);
tft.fillRect(nx-12, ny-2, 24, 10, ILI9341_YELLOW);
}
void dinamikIcerikCiz(struct tm *ti) {
// YAZILI PROGRAMI (30 Mart Türkçe, 31 Mart Fen)
tft.setCursor(5, 45);
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.println("YAZILI PROGRAMI");
tft.setTextSize(1);
for(int i=0; i<6; i++) {
int sGun = (sinavlar[i].a == 3) ? sinavlar[i].g : (31 + sinavlar[i].g);
int bGun = ((ti->tm_mon + 1) == 3) ? ti->tm_mday : (31 + ti->tm_mday);
int kalan = sGun - bGun;
tft.setCursor(5, 65 + (i*13));
if(kalan == 0) tft.setTextColor(ILI9341_YELLOW);
else if(kalan < 0) tft.setTextColor(0x7BEF);
else tft.setTextColor(ILI9341_WHITE);
tft.printf("%s: %d Gun Kaldi", sinavlar[i].ad, (kalan < 0 ? 0 : kalan));
}
// DERS PROGRAMI (7-C Programı)
tft.drawFastHLine(5, 150, 230, ILI9341_WHITE);
tft.setCursor(5, 158);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("DERS PROGRAMI");
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
int gun = ti->tm_wday - 1;
if(gun >= 0 && gun <= 4) {
for(int d=0; d<7; d++) {
tft.setCursor(10, 178 + (d*12));
tft.printf("%d. %s", d+1, program[gun][d]);
}
} else {
tft.setCursor(10, 185);
tft.println("Haftasonu! Dinlen :)");
}
}