#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Wire.h>
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Mittelpunkt der Drehzahlanzeige
int centerX = 120;
int centerY = 160;
void setup() {
tft.begin();
tft.fillScreen(ILI9341_BLACK); // Hintergrund auf Schwarz setzen
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can has colors?");
}
void loop() {
// Drehzahlanzeige zeichnen
drawTachometer(100); // Hier die aktuelle Geschwindigkeit (in Umdrehungen pro Minute) eintragen
delay(1000); // Eine Sekunde warten, bevor die Anzeige aktualisiert wird
}
// Funktion zum Zeichnen der Drehzahlanzeige
void drawTachometer(int rpm) {
tft.fillCircle(centerX, centerY, 100, ILI9341_BLACK); // Hintergrund löschen
int angle = map(rpm, 0, 10000, 0, 360); // Geschwindigkeit in Grad umwandeln
angle = constrain(angle, 0, 360); // Winkel begrenzen
// Zeiger zeichnen
int x2 = centerX + 80 * cos((angle - 90) * DEG_TO_RAD);
int y2 = centerY + 80 * sin((angle - 90) * DEG_TO_RAD);
tft.drawLine(centerX, centerY, x2, y2, ILI9341_RED);
tft.fillCircle(centerX, centerY, 5, ILI9341_RED);
// Geschwindigkeit anzeigen
tft.setCursor(110, 200);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print(rpm);
tft.print(" RPM");
}