#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <XPT2046_Touchscreen.h>
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_CLK 18
#define SD_CS 21
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
#define TOUCH_CS 27
XPT2046_Touchscreen ts(TOUCH_CS);
#define SOIL_SENSOR_PIN 34
#define RELAY_PIN 5
#define ENCODER_CLK_PIN 32
#define ENCODER_DT_PIN 33
#define ENCODER_SW_PIN 25
#define MANUAL_BTN_PIN 26
void drawIconWithLabel(const char* filename, int y, const char* label) {
if (!SD.exists(filename)) {
Serial.print("Datei nicht gefunden: ");
Serial.println(filename);
return;
}
File bmpFile = SD.open(filename);
if (!bmpFile) {
Serial.print("Konnte Datei nicht öffnen: ");
Serial.println(filename);
return;
}
// BMP-Header lesen
uint8_t bmpHeader[54];
bmpFile.read(bmpHeader, 54);
// BMP-Breite und Höhe lesen
int bmpWidth = bmpHeader[18] + (bmpHeader[19] << 8);
int bmpHeight = bmpHeader[22] + (bmpHeader[23] << 8);
// BMP zeichnen
tft.drawRGBBitmap(40, y, bmpFile, bmpWidth, bmpHeight);
bmpFile.close();
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(100, y + 15); // Position anpassen, wenn nötig
tft.print(label);
}
void drawMainMenu() {
// Zeichnen der Statusleiste
tft.fillRect(0, 0, 320, 60, 0x00D4FF); // Türkiser Rand
tft.fillRect(3, 3, 314, 54, 0xA7E8F2); // Hell-türkise Füllung
// Text für Status, Feuchtigkeit und Uhrzeit
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.print("Status: Active");
tft.setCursor(10, 30);
tft.print("Feuchtigkeit: 50%");
tft.setCursor(220, 10);
tft.print("12:00");
}
void setup() {
Serial.begin(115200);
pinMode(SOIL_SENSOR_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
pinMode(ENCODER_CLK_PIN, INPUT);
pinMode(ENCODER_DT_PIN, INPUT);
pinMode(ENCODER_SW_PIN, INPUT_PULLUP);
pinMode(MANUAL_BTN_PIN, INPUT_PULLUP);
tft.begin();
ts.begin();
ts.setRotation(1);
drawMainMenu();
}
void loop() {
int soilMoistureValue = analogRead(SOIL_SENSOR_PIN);
// Serial.print("Soil Moisture: ");
// Serial.println(soilMoistureValue);
// Add more logic for reading encoder, button, and controlling relay
}