#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// #include <XPT2046_Touchscreen.h>
#include <Adafruit_FT6206.h>
#include <iostream>
#include <Arduino.h>
#include <DHT.h>
#include <DHT_U.h>
#include <ctype.h> // Für die tolower-Funktion
//#include <Fonts/FreeSans9pt7b.h> // Einbinden der Schriftart
#include <HX711.h>
#include "plantboyfont.h"
#include "bmphelper.h"
#include "input.h"
// Pins for the ILI9341 display
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_MISO 19
#define TFT_LED 14
// HX711 Pins
#define LOADCELL_DOUT_PIN 0
#define LOADCELL_SCK_PIN 16
// HX711-Objekt erstellen
HX711 scale;
// Pins für den Touchscreen (ändern Sie diese, wenn nötig)
#define TOUCH_CS 7
#define TOUCH_IRQ 2
// Pin for the SD card module
#define SD_CS 5
#define RIGHT_BORDER 10
#define HEADER_GAP 10
// Pin für den DHT22-Sensor
#define DHTPIN 17
#define DHTTYPE DHT22
// Settings
bool scales_calibrated = false;
// Alphabet-Array
char alphabet[26] = {
'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z'
};
// Variable zur Speicherung der letzten Aktualisierungszeit
unsigned long lastTouch; // Last touch at all
unsigned long lastDHTRefreshTime;
unsigned long lastWeightRefreshTime;
bool displayOff = false;
unsigned long lastTouchTime = 0;
const unsigned long touchInterval = 100; // Intervall von 100 ms
// Bereichsdefinitionen
const int startX = 27;
const int startY = 138;
const int width = 268;
const int height = 102;
const int buttonSpacing = 6;
const int numButtonsPerRow = 5;
// Größe eines Buttons berechnen (wir ignorieren den zehnten Button)
const int buttonWidth = 48;
const int buttonHeight = 48;
// Views
typedef enum openView {
UNDEFINED,
MAIN_MENU,
KEYBOARD,
STATS,
PLANTS,
SETTINGS,
HARVEST,
START_SCALES_CALIBRATION,
SCALES_CALIBRATION,
};
typedef enum statsPropertyType {
TEMPERATURE,
HUMIDITY,
WEIGHT
};
openView currentView; // = MAIN_MENU;
openView lastOpenedView; // = UNDEFINED;
bool viewNeedsToRefresh = false;
// Modal
typedef enum feedbackType {
SUCCESS,
ERROR,
};
uint16_t screenBuffer[320 * 240];
// Keyboard things
int currentPage = 1;
bool shiftOn = true;
// Config
File configFile;
// Settings
#define INACTIVITY_TIMEOUT 120000 // 2 minutes in milliseconds
enum iconType {
BATTERY,
WIFI,
};
enum iconState {
ACTIVE,
INACTIVE,
STANDBY,
};
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
DHT dht(DHTPIN, DHTTYPE);
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// XPT2046_Touchscreen ts(TOUCH_CS, TOUCH_IRQ);
// Helper for View
void setView(openView view) {
lastOpenedView = currentView;
currentView = view;
}
void backToLastView() {
currentView = lastOpenedView;
lastOpenedView = UNDEFINED;
}
String utf8ToWindows(String s) {
String res = ""; //String for result
uint8_t prev = 0; //to remember previous character
uint8_t c; //current character
for (uint16_t i = 0; i<s.length(); i++) { //we iterate over the source string
c = byte(s[i]); //get next character
if (c < 0x80) {
res += char(c); //less then 0x80 -> standard ASCII
} else {
switch (prev) {
case 0xC2 : res += char(c); break;
// if previous character code was 0xc2, we can use character as is
case 0xC3 : res += char(c | 0x40); break;
// if prvious character code was 0xc3, we need to set bit 7
case 0x82 : if (c == 0xac) res += char(0x80); break;
//special handling for Euro character
} //other UTF8 characters will be ignored
}
prev = c; //remember currend character for next loop
}
return res;
}
// ----- Some objects to draw
void drawBox(int x, int y, int width, const String& text, const String& symbol = "") {
int height = 40; // Fixed height of the box
int radius = 5; // Radius for rounded corners
// Draw the outer rectangle (border)
tft.drawRoundRect(x, y, width, height, radius, ILI9341_DARKGREY);
// Fill the inner rectangle
tft.fillRoundRect(x + 1, y + 1, width - 2, height - 2, radius, ILI9341_LIGHTGREY);
// Set font and text size
tft.setFont(&plantboyfont);
tft.setTextSize(2);
tft.setTextColor(ILI9341_BLACK, ILI9341_LIGHTGREY);
// Draw the text on the left
tft.setCursor(x + 5, y + height / 2 + 10); // Adjust the Y coordinate to vertically center the text
tft.print(utf8ToWindows(text));
// Draw the symbol on the right (if provided)
if (symbol.length() > 0) {
int16_t x1, y1;
uint16_t w, h;
tft.getTextBounds(utf8ToWindows(symbol), x, y, &x1, &y1, &w, &h);
tft.setCursor(x + width - w - 5, y + height / 2 + 10); // Adjust the Y coordinate to vertically center the text
tft.print(utf8ToWindows(symbol));
}
}
// ----- Some objects to draw
// ----- MODAL
void showFeedbackModal(feedbackType feedback) {
int x = tft.width() / 2 - 75, y = tft.height() / 2 - 60;
// Modal anzeigen
tft.fillRoundRect(x, y, 150, 120, 5, ILI9341_WHITE);
tft.drawRoundRect(x, y, 150, 120, 5, ILI9341_BLACK);
tft.setCursor(x + 10, y + 15);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(1);
if (feedback == SUCCESS) {
tft.print("Erfolg!");
rawDraw(tft, "/icon_success.raw", x + (75 - 37.5), y + (60 - 37.5 + 15), 75, 75);
} else {
tft.print("Ups, das ging schief!");
rawDraw(tft, "/icon_error.raw", x + (75 - 37.5), y + (60 - 37.5 + 15), 75, 75);
}
delay(1500);
currentView = lastOpenedView;
viewNeedsToRefresh = true;
}
// ----- MODAL
// ----- CONFIG
// Funktion zum Lesen eines Parameters aus der INI-Datei
String getConfigValue(const String& paramName) {
// Überprüfen, ob die SD-Karte initialisiert ist
// if (!SD.begin(SD_CS)) {
// Serial.println("SD-Karte konnte nicht initialisiert werden");
// return "";
// }
// Überprüfen, ob die config.ini Datei existiert
if (!SD.exists("/config.ini")) {
// Datei erstellen und eine Beispielkonfiguration schreiben
configFile = SD.open("/config.ini", FILE_WRITE);
if (configFile) {
configFile.println("[Settings]");
configFile.println("scales_calibrated=0");
configFile.println("wlan_password=null");
configFile.close();
Serial.println("config.ini Datei erstellt.");
} else {
Serial.println("Konnte config.ini Datei nicht erstellen.");
return "";
}
}
// Datei zum Lesen öffnen
configFile = SD.open("/config.ini", FILE_READ);
if (!configFile) {
Serial.println("Konnte config.ini Datei nicht öffnen.");
return "";
}
// Parameter in der Datei suchen
String line;
String value = "";
while (configFile.available()) {
line = configFile.readStringUntil('\n');
line.trim();
if (line.startsWith(paramName + "=")) {
value = line.substring(paramName.length() + 1);
break;
}
}
configFile.close();
return value;
}
bool setConfigValue(const String& paramName, const String& paramValue) {
// Überprüfen, ob die SD-Karte initialisiert ist
if (!SD.begin(SD_CS)) {
Serial.println("SD-Karte konnte nicht initialisiert werden");
return false;
}
// Überprüfen, ob die config.ini Datei existiert
if (!SD.exists("/config.ini")) {
// Datei erstellen und eine Beispielkonfiguration schreiben
configFile = SD.open("/config.ini", FILE_WRITE);
if (configFile) {
configFile.println("[Settings]");
configFile.println("scales_calibrated=0");
configFile.println("wlan_password=null");
configFile.close();
Serial.println("config.ini Datei erstellt.");
} else {
Serial.println("Konnte config.ini Datei nicht erstellen.");
return false;
}
}
// Datei zum Lesen öffnen
configFile = SD.open("/config.ini", FILE_READ);
if (!configFile) {
Serial.println("Konnte config.ini Datei nicht öffnen.");
return false;
}
// Ganze Datei einlesen
String fileContent = "";
String line;
bool found = false;
while (configFile.available()) {
line = configFile.readStringUntil('\n');
line.trim();
if (line.startsWith(paramName + "=")) {
line = paramName + "=" + paramValue;
found = true;
}
fileContent += line + "\n";
}
configFile.close();
// Falls der Parameter nicht gefunden wurde, fügen wir ihn hinzu
if (!found) {
fileContent += paramName + "=" + paramValue + "\n";
}
// Datei zum Schreiben öffnen
configFile = SD.open("/config.ini", FILE_WRITE);
if (!configFile) {
Serial.println("Konnte config.ini Datei nicht zum Schreiben öffnen.");
return false;
}
// Aktualisierten Inhalt zurückschreiben
configFile.print(fileContent);
configFile.close();
return true;
}
// ----- CONFIG
// ----- HEADER
void drawHeader() {
// Header height = 18px
tft.fillRect(0, 0, tft.width(), 18, ILI9341_LIGHTGREY);
}
void setHeaderIcon(iconType icon, iconState state = ACTIVE) {
if (icon == BATTERY) {
//tft.fillRect(tft.width() - 15 - RIGHT_BORDER, 0, 15, 15, ILI9341_LIGHTGREY);
rawDraw(tft, "/battery.raw", tft.width() - 15 - RIGHT_BORDER, 1, 15, 15);
}
if (icon == WIFI) {
// 15 * 2 = second icon / HEADER_GAP * 1 = one icon before
switch (state) {
case ACTIVE:
rawDraw(tft, "/wifi_connected.raw", tft.width() - (15 * 2) - RIGHT_BORDER - (HEADER_GAP * 1), 1, 15, 15);
break;
case INACTIVE:
rawDraw(tft, "/wifi_disconnected.raw", tft.width() - (15 * 2) - RIGHT_BORDER - (HEADER_GAP * 1), 1, 15, 15);
break;
case STANDBY:
rawDraw(tft, "/wifi_loading.raw", tft.width() - (15 * 2) - RIGHT_BORDER - (HEADER_GAP * 1), 1, 15, 15);
break;
}
}
}
// ----- HEADER
void setHeaderTitle(const String& title) {
tft.fillRect(10, 0, 200, 18, ILI9341_LIGHTGREY);
tft.setFont(&plantboyfont); // Setzt die Schriftart
tft.setTextColor(ILI9341_BLACK, ILI9341_LIGHTGREY);
tft.setTextSize(1);
tft.setCursor(10, 12);
tft.print(utf8ToWindows(title));
}
// ----- VIEWS
void drawKeyboard(int page, int x, int y) {
setView(KEYBOARD);
if (page > 3) {
page = 3;
}
// Dateinamen in einem Array speichern (einmal pro Aufruf)
char* imageNames[26] = {
"/letter_A.raw", "/letter_B.raw", "/letter_C.raw", "/letter_D.raw", "/letter_E.raw", "/letter_F.raw",
"/letter_G.raw", "/letter_H.raw", "/letter_I.raw", "/letter_J.raw", "/letter_K.raw", "/letter_L.raw",
"/letter_M.raw", "/letter_N.raw", "/letter_O.raw", "/letter_P.raw", "/letter_Q.raw", "/letter_R.raw",
"/letter_S.raw", "/letter_T.raw", "/letter_U.raw", "/letter_V.raw", "/letter_W.raw", "/letter_X.raw",
"/letter_Y.raw", "/letter_Z.raw"
};
// Bilder vorladen (optional)
// ... (Implementierung der Bildvorladefunktion)
int counter = 0, yPos = y, startX = x;
// Zeichne die 9 Buchstaben der aktuellen Seite
for (int i = 0; i < 9; i++) {
// Dateinamen aus dem Array abrufen
char* imageName = imageNames[i + (9 * (page - 1))];
Serial.println(i + (9 * (page - 1)));
// Zeichne den Buchstaben
if (counter > 4) {
x = startX;
counter = 0;
yPos += buttonSpacing + 48;
}
if (i + (9 * (page - 1)) > 25) {
tft.fillRect(x, yPos, 48, 48, ILI9341_WHITE);
} else {
rawDraw(tft, imageName, x, yPos, 48, 48);
}
// Positionierung aktualisieren
x += 48 + buttonSpacing;
counter++;
}
// Draw shift and back/next buttons
if (shiftOn) {
rawDraw(tft, "/shift_active.raw", 4 * (48 + buttonSpacing) + startX, y + 48 + buttonSpacing, 48, 48);
} else {
rawDraw(tft, "/shift_inactive.raw", 4 * (48 + buttonSpacing) + startX, y + 48 + buttonSpacing, 48, 48);
}
if (page == 1) {
rawDraw(tft, "/back_inactive.raw", 0, y, 20, 102);
} else {
rawDraw(tft, "/back_active.raw", 0, y, 20, 102);
}
if (page == 3) {
rawDraw(tft, "/next_inactive.raw", tft.width() - 20, y, 20, 102);
} else {
rawDraw(tft, "/next_active.raw", tft.width() - 20, y, 20, 102);
}
}
void drawStats() {
// Check if scales already calibrated
if (getConfigValue("scales_calibrated") == "0") {
lastOpenedView = currentView;
currentView = START_SCALES_CALIBRATION;
viewNeedsToRefresh = true;
return;
}
tft.fillRect(0, 19, tft.width(), tft.height(), ILI9341_WHITE);
rawDraw(tft, "/icon_temperature.raw", 20, 20, 48, 48);
rawDraw(tft, "/icon_humidity.raw", 20, 80, 48, 48);
rawDraw(tft, "/icon_weight.raw", 20, 140, 48, 48);
}
void drawStatsProperty(statsPropertyType type, const String& value) {
if (type == TEMPERATURE) {
drawBox(75, 24, 200, value, "°C");
} else if (type == HUMIDITY) {
drawBox(75, 84, 200, value, "%");
} else if (type == WEIGHT) {
drawBox(75, 144, 200, value, "KG");
rawDraw(tft, "/button_tare.raw", 129, 185, 96, 48);
}
}
void refreshStats() {
// Lese Daten vom DHT22-Sensor
if (millis() - lastDHTRefreshTime > 10000) {
lastDHTRefreshTime = millis();
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Überprüfen ob die Messungen gültig sind
if (isnan(humidity) || isnan(temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
char tempBuffer[10];
dtostrf(temperature, 4, 1, tempBuffer);
String tempString = String(tempBuffer);
drawStatsProperty(TEMPERATURE, tempString);
char humidityBuffer[10];
dtostrf(humidity, 4, 1, humidityBuffer);
String humidityString = String(humidityBuffer);
drawStatsProperty(HUMIDITY, humidityString);
drawStatsProperty(WEIGHT, "1.125");
}
if (millis() - lastWeightRefreshTime > 500) {
float weight = scale.get_units(10); // Durchschnitt von 10 Messungen
Serial.print("Gewicht: ");
Serial.print(weight);
Serial.println(" g");
}
}
void drawStartScalesCalibration() {
// Start calibration...
tft.setFont(&plantboyfont); // Setzt die Schriftart
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setTextSize(1);
if (currentView == START_SCALES_CALIBRATION) {
tft.fillRect(0, 19, tft.width(), tft.height(), ILI9341_WHITE);
const String text = "Bitte belaste die Waage mit";
const String text2 = "500g und drücke dann Start.";
int16_t x1, y1;
uint16_t w, h;
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
tft.setCursor(tft.width() / 2 - (w / 2), 60);
tft.print(text);
tft.getTextBounds(text2, 0, 0, &x1, &y1, &w, &h);
tft.setCursor(tft.width() / 2 - (w / 2), 80);
tft.print(text2);
rawDraw(tft, "/button_start_calibration.raw", tft.width() / 2 - 125, 120, 250, 50);
} else if (currentView == SCALES_CALIBRATION) {
tft.fillRect(0, 19, tft.width(), tft.height(), ILI9341_WHITE);
tft.setFont(&plantboyfont); // Setzt die Schriftart
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setTextSize(2);
int16_t x1, y1;
uint16_t w, h;
tft.getTextBounds("Bitte stillhalten...", 0, 0, &x1, &y1, &w, &h);
tft.setCursor(tft.width() / 2 - (w / 2), tft.height() / 2 - (h / 2) + 10);
tft.print("Bitte stillhalten...");
delay(1000);
scale.set_scale(); // setze den aktuellen Wert auf 0
scale.tare(); // setze den aktuellen Wert auf 0
delay(1000);
float known_weight = 500.0; // Beispiel: 500 Gramm
scale.set_scale(scale.get_units() / known_weight); // Kalibrierung des Skalierungsfaktors
showFeedbackModal(SUCCESS);
currentView = lastOpenedView;
viewNeedsToRefresh = true;
}
}
// ----- VIEWS
void switchKeyboardShift() {
if (shiftOn) {
rawDraw(tft, "/shift_active.raw", 4 * (48 + buttonSpacing) + startX, startY + 48 + buttonSpacing, 48, 48);
} else {
rawDraw(tft, "/shift_inactive.raw", 4 * (48 + buttonSpacing) + startX, startY + 48 + buttonSpacing, 48, 48);
}
}
// ----- DISPLAY
void sleepDisplay() {
digitalWrite(TFT_LED, LOW); // Hintergrundbeleuchtung ausschalten
tft.writeCommand(ILI9341_DISPOFF); // Display ausschalten
tft.writeCommand(ILI9341_SLPIN); // Display in den Schlafmodus versetzen
displayOff = true; // Set display to OFF
}
void wakeDisplay() {
tft.writeCommand(ILI9341_SLPOUT); // Display aus dem Schlafmodus holen
tft.writeCommand(ILI9341_DISPON); // Display einschalten
digitalWrite(TFT_LED, HIGH); // Hintergrundbeleuchtung einschalten
displayOff = false;
}
// ----- DISPLAY
// Funktion zur Bestimmung des geklickten Buttons
char getClickedButton(int clickX, int clickY) {
// Berechnung der relativen Position innerhalb des Bereichs
int relativeX = clickX - startX;
int relativeY = clickY - startY;
// Überprüfung, ob der Klick innerhalb des Bereichs liegt
if (relativeX < 0 || relativeX >= width || relativeY < 0 || relativeY >= height) {
return '\0'; // Außerhalb des Bereichs geklickt
}
// Berechnung der Zeile und Spalte
int row = relativeY / (buttonHeight + buttonSpacing);
int col = relativeX / (buttonWidth + buttonSpacing);
Serial.println(row);
Serial.println(col);
Serial.println(relativeX);
// Berechnung des Index im Alphabet-Array
int index = row * (numButtonsPerRow) + col;
// Überprüfung, ob der Klick auf den Shift Button erfolgt ist
if (index % 9 == 0) {
shiftOn = !shiftOn;
switchKeyboardShift();
return '^';
}
// Überprüfung, ob der Index gültig ist
if (index >= 0 && index < 26) {
if (shiftOn) {
return alphabet[index]; // Der Buchstabe aus dem Alphabet-Array
} else {
return tolower(alphabet[index]);
}
}
return '\0'; // Ungültiger Index
}
openView getClickedMenuButton(int clickX, int clickY) {
if (clickX >= 60 && clickX <= 150 && clickY >= 40 && clickY <= 130) { // Menu one
return STATS;
} else if (clickX >= 170 && clickX <= 260 && clickY >= 40 && clickY <= 130) { // Menu two
return HARVEST;
} else if (clickX >= 60 && clickX <= 150 && clickY >= 140 && clickY <= 230) { // Menu three
return PLANTS;
} else if (clickX >= 170 && clickX <= 260 && clickY >= 140 && clickY <= 230) { // Menü four
return SETTINGS;
}
// No menu was clicked
return UNDEFINED;
}
// Main touch handler
void touchHandler() {
if (ctp.touched()) {
lastTouch = millis();
if (displayOff) { // Display is in standby? Wake it and wait 200 ms
wakeDisplay();
delay(300);
return;
}
unsigned long currentTime = millis();
// Prüfen, ob das Intervall seit dem letzten Touch-Ereignis vergangen ist
if (currentTime - lastTouchTime > touchInterval) {
// rotate coordinate system
TS_Point p = ctp.getPoint();
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
int y = p.x;
int x = tft.width() - p.y;
if (currentView == KEYBOARD) {
// back button pressed
if (x >= 0 && x <= 20 && y >= tft.height() - 102 && y <= tft.height()) {
if (currentPage > 1) {
currentPage--;
drawKeyboard(currentPage, 27, tft.height() - 48 - buttonSpacing - 48);
}
}
// forward button pressed
if (x >= tft.width() - 20 && x <= tft.width() && y >= tft.height() - 102 && y <= tft.height()) {
if (currentPage < 3) {
currentPage++;
drawKeyboard(currentPage, 27, tft.height() - 48 - buttonSpacing - 48);
}
}
char clickedButton = getClickedButton(x, y);
if (clickedButton != '\0') {
Serial.print("Clicked on button: ");
Serial.println(clickedButton);
} else {
Serial.println("Clicked outside the button area or invalid button.");
}
Serial.print(x);
Serial.print(" - ");
Serial.println(y);
} else if (currentView == MAIN_MENU) {
openView clickedMenu = getClickedMenuButton(x, y);
if (clickedMenu != UNDEFINED) {
lastOpenedView = currentView;
currentView = clickedMenu;
// Refresh view in next cycle...
viewNeedsToRefresh = true;
}
} else if (currentView == START_SCALES_CALIBRATION) {
// tft.width() / 2 - 125, 120, 250, 50
if (x >= tft.width() / 2 - 125 && x <= tft.width() / 2 + 125 && y >= 120 && y <= 170) {
// Don't set last view! We need the current last view later
currentView = SCALES_CALIBRATION;
// Refresh view in next cycle...
viewNeedsToRefresh = true;
}
}
// Aktualisieren der letzten Touch-Zeit
lastTouchTime = currentTime;
}
}
}
void setup() {
currentView = MAIN_MENU;
lastOpenedView = UNDEFINED;
Serial.begin(115200);
Wire.begin(21, 22); // Redefine the first I2C port to be on pins 10/8
// Initialize ILI9341
tft.begin();
tft.setRotation(1); // Landscape orientation
// Set pin and enable display light
pinMode(TFT_LED, OUTPUT);
digitalWrite(TFT_LED, HIGH); // Hintergrundbeleuchtung einschalten
// Initialize SD card
if (!SD.begin(SD_CS)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
starting(tft); // Loading screen
// Initialisiert den DHT22-Sensor
dht.begin();
// Initialisiere den HX711
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
if (!ctp.begin(40)) { // Pass in the 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
// Set all millis they needed
lastDHTRefreshTime = millis() + 10000; // For first time + 10 seconds
lastWeightRefreshTime = millis() + 10000; // For first time + 10 seconds
// Get important settings...
String scale = getConfigValue("scales_calibrated");
if (scale != "" && scale != "0") {
scales_calibrated = true;
}
delay(100);
tft.fillScreen(ILI9341_WHITE);
// List files on SD card
//listFiles("/");
drawHeader();
setHeaderIcon(BATTERY);
setHeaderIcon(WIFI, STANDBY);
viewNeedsToRefresh = true;
// drawKeyboard(1, 27, tft.height() - 48 - buttonSpacing - 48);
// initializeInputField(tft, 10, 10, 300, 30); // Beispielwerte
// processInput(tft, "H");
// processInput(tft, "a");
// Test reading and displaying a BMP file
// if (!rawDraw(tft, "/test.raw", 0, 0, 52, 52)) {
// Serial.println("Failed to load image");
// }
// if (!rawDraw(tft, "/test2.raw", 62, 0, 52, 52)) {
// Serial.println("Failed to load image");
// }
}
void loop() {
if (viewNeedsToRefresh) {
viewNeedsToRefresh = false;
if (currentView == MAIN_MENU) {
drawMainMenu(tft);
setHeaderTitle("Menü");
} else if (currentView == STATS) {
// showFeedbackModal(ERROR);
drawStats();
setHeaderTitle("Werte");
} else if (currentView == START_SCALES_CALIBRATION || currentView == SCALES_CALIBRATION) {
drawStartScalesCalibration();
setHeaderTitle("Kalibrierung");
}
}
if (currentView == STATS && scales_calibrated) {
Serial.println(getConfigValue("scales_calibrated"));
refreshStats();
}
touchHandler();
// // Lese Daten vom DHT22-Sensor
// float humidity = dht.readHumidity();
// float temperature = dht.readTemperature();
// // Überprüfen ob die Messungen gültig sind
// if (isnan(humidity) || isnan(temperature)) {
// Serial.println(F("Failed to read from DHT sensor!"));
// return;
// }
// // Ausgabe der Messwerte in der seriellen Konsole
// Serial.print(F("Humidity: "));
// Serial.print(humidity);
// Serial.print(F("% Temperature: "));
// Serial.print(temperature);
// Serial.println(F("°C "));
// // Warte 2 Sekunden bevor erneut gelesen wird
// delay(2000);
// if (ctp.touched()) {
// unsigned long currentTime = millis();
// // Prüfen, ob das Intervall seit dem letzten Touch-Ereignis vergangen ist
// if (currentTime - lastTouchTime > touchInterval) {
// // Retrieve a point
// TS_Point p = ctp.getPoint();
// // rotate coordinate system
// // flip it around to match the screen.
// p.x = map(p.x, 0, 240, 240, 0);
// p.y = map(p.y, 0, 320, 320, 0);
// int y = p.x;
// int x = tft.width() - p.y;
// Serial.print(x);
// Serial.print(" - ");
// Serial.println(y);
// // Aktualisieren der letzten Touch-Zeit
// lastTouchTime = currentTime;
// }
// }
if (millis() - lastTouch >= INACTIVITY_TIMEOUT && !displayOff) {
Serial.println("Display goes sleeping");
sleepDisplay();
}
}
Loading
ili9341-cap-touch
ili9341-cap-touch