/*
Beispiel für
https://forum.arduino.cc/t/tft-input-placeholder/1107597
2023-03-28
ec2021
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define LEFT 50
#define TOP 80
#define ZEICHENBREITE 24
struct CursorType {
int x;
int y;
int textSize = 1;
int width;
int Position = 0;
uint16_t color;
void Draw();
void Delete();
};
void CursorType::Draw(){
tft.fillRect(CursorType::x+CursorType::Position*(CursorType::textSize)*6,
CursorType::y+(CursorType::textSize +1)*6,
CursorType::textSize * 6,
CursorType::width,
CursorType::color);
}
void CursorType::Delete(){
uint16_t oldCol = CursorType::color;
CursorType::color = ILI9341_BLACK;
CursorType::Draw();
CursorType::color = oldCol;
}
CursorType myCursor;
void Cursor(int Stelle){
static unsigned long lastChange = 0;
static boolean Paint = true;
static int lastStelle = 0;
if (lastStelle != Stelle) {
myCursor.Position = lastStelle;
myCursor.Delete();
lastChange = 0;
lastStelle = Stelle;
Paint = true;
}
if (millis()-lastChange > 300){
myCursor.Position = lastStelle;
lastChange = millis();
if (Paint) {
myCursor.Draw();
} else {
myCursor.Delete();
}
Paint = !Paint;
}
}
// --------------------------------------
// Hier die textSize anpassen ...
int textSize = 6;
// --------------------------------------
void setup() {
tft.begin();
tft.setCursor(LEFT, TOP);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(textSize);
// 4 -> y = TOP +30 ZEICHENBREITE = 24
// 3 -> y = TOP +24 ZEICHENBREITE = 18
// 2 -> y = TOP +18 ZEICHENBREITE = 12
// 1 -> y = TOP +12 ZEICHENBREITE = 6
myCursor.x = LEFT;
myCursor.y = TOP;
myCursor.textSize = textSize;
myCursor.width = 3;
myCursor.color = ILI9341_RED;
tft.println("00:00");
}
int Stelle = 0;
unsigned long lastChange = 0;
void loop() {
Cursor(Stelle);
if (millis()-lastChange > 3000){
lastChange = millis();
Stelle++;
if (Stelle == 2) Stelle++; // Hier ist der Doppelpunkt
if (Stelle > 4) Stelle = 0;
}
}