Hallöchen zusammen.
ich habe wieder einmal ein kleines Problem. Ich bin seit Stunden am googeln und finde einfach nix.
Bei meinem WoMo-Monitor möchte ich die Text-Buttons durch Bilder ersetzen. Dafür bräuchte ich eigentlich nur einen "durchsichtigen" Button. Da kommt jetzt aber das Problem. Bei der mcufriends Bibliothek muss ich ja 3 Farben angeben: Rahmen, Hintergrund und Text. Wenn ich Hintergrund und Text aber schwarz mache, dann funktioniert das beim ersten Anzeigen. Wenn ich aber den Screen das 2.Mal anzeige, wird das Icon vom Button überzeichnet, und der Button funktioniert nur noch auf dem Rahmen des Buttons
Benutzt wird ein Arduino Mega und ein 3.5" Display das direkt auf den Arduino aufgesteckt wird.
Der Rest vom Sketch funzt auch, aber dieses Icon will nicht.
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <Adafruit_TFTLCD.h> // Hardware-specific library
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#include"pitches.h"
#include"icons.h"
//Uhr
#include <Wire.h> //Wire Bibliothek einbinden
#include <RTClib.h> //Real Time Clock Bibliothek einbinden
//Temp Sensor
#include "DHT.h" //Temp/Feuchtigkeitssensor Bibliothek einbinden
//Uhr definieren
RTC_DS1307 rtc; //Uhr benennen
#define RST_PIN -1 //Reset Pin nicht vorhanden --> also -1
//Temperatursensor definieren
#define DHTPIN 31 //Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 //DHT 22
DHT dht(DHTPIN, DHTTYPE); //Sensor benennen
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#include <FreeDefaultFonts.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
//3.5 Calibration
const int XP = 6, XM = A2, YP = A1, YM = 7; //320x480 ID=0x9486
const int TS_LEFT = 942, TS_RT = 183, TS_TOP = 967, TS_BOT = 187;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint p;
Adafruit_GFX_Button on_btn, off_btn, page1_btn, page2_btn, page3_btn, page4_btn, page5_btn, page6_btn;
Adafruit_GFX_Button ok_btn, cncl_btn, plus_btn, minus_btn;
Adafruit_GFX_Button menu_btn, info_btn, back_btn, next_btn;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
// Button calibration
int margin = 5;
int btnWidth = 100;
int btnHeight = 40;
int btnY = 200;
// Software variable
bool enable_nuit = false;
int parameter = 50, old_parameter = 50;
const int rotar = 1; //Display Rotation
//Uhrzeitvariablen
String Datumget;
String Uhrget;
String Tagnow;
String Wochentag;
String Datumget_alt;
String Uhrget_alt;
String Tagnow_alt;
String Wochentag_alt;
byte ControllerUhr = 0;
//Temperaturvariablen
float h, h_alt, t, t_alt;
//Batterien
float Aufbaubatterie, Bordbatterie;
//Wasserstandvariablen
int Wasserstand;
int Liner = 250;
//Gauge Variablen
#define RED2RED 0
#define GREEN2GREEN 1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN 5
uint32_t runTime = -99999; // time for next update
//Ein paar Farben definieren
#define BLACK 0x0000
#define GREY 0x5555
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define DARKGREEN 0x05C0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define GOLD 0xDDC0
#define WHITE 0xFFFF
#define DARKGREY 0x10A2
enum pageId {
MENU,
INFO,
BATTERIE,
WATER,
INFO1,
ALARM,
REALALARM,
SOLAR,
SOLAR1,
SOLAR2,
WETTER
};
unsigned int currentPage = MENU, oldPage = -1;
//Tonausgabe
int tonPin = 45;
//Solarvariablen
float SolarAmps, SolarAmps2, SolarVolts, BatAmps, BatVolts;
int SolarWatts;
void setup(void)
{
Serial.begin(9600);
//init TFTTouch
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println(F("Calibrate for your Touch Panel"));
if (ID == 0xD3D3) ID = 0x9486; //for 3.5" TFT LCD Shield , 0x9341 for 2.8" TFT LCD Shield
tft.begin(ID);
tft.setRotation(rotar); //0-PORTRAIT 1-PAYSAGE 2-REVERSE PORTRAIT 3-REVERSE PAYSAGE
//tft.setFont(&FreeSmallFont);
/*if (!SD.begin(SD_CS)) {
Serial.println(F("initialization failed!"));
return;
}*/
currentPage = MENU; // Indicates that we are at Home Screen
Serial.println("Home Page");
//Uhr
#ifndef ESP8266 //Wenn ein ESP8266 angeschlossen ist
while (!Serial); // auf den Seriellen Port warten. Dieser wird für natives USB benötigt
#endif
if (! rtc.begin()) { //Wenn rtc.begin fehlschlägt
Serial.println("Konnte die RTC nicht starten"); //Ausgabe auf den seriellen Monitor
Serial.flush(); //Seriellen Monitor leeren
abort(); //abbrechen
}
delay(1000); //1 Sekunde warten
if (! rtc.isrunning()) { //Wenn RTC nicht läuft
Serial.println("RTC läuft nicht, also müssen wir die Zeit einstellen");
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Daten von Systemzeit holen
// rtc.adjust(DateTime(2023, 6, 23, 18, 7, 30)); //Datum und Uhrzeit manuell eingeben (ohne anführende Nullen
}
// Wenn nur Zeit/Datum eingestellt werden muss
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Daten von Systemzeit holen
// rtc.adjust(DateTime(2023, 6, 23, 18, 7, 30)); //Datum und Uhrzeit manuell eingeben (ohne anführende Nullen
getUhrzeit();
// Temperatursensor
dht.begin(); //DHT Sensor starten
//Wire starten
Wire.begin();
Wire.setClock(400000L);
//Wasserstand holen
getWasser();
pinMode(tonPin, OUTPUT);
}
//Ende Setup
bool down ;
void loop(void) {
switch (currentPage) {
case MENU: //Menu page
if (currentPage != oldPage) drawMenuScreen();
page1_btn.press(down && page1_btn.contains(pixel_x, pixel_y));
page2_btn.press(down && page2_btn.contains(pixel_x, pixel_y));
page3_btn.press(down && page3_btn.contains(pixel_x, pixel_y));
page4_btn.press(down && page4_btn.contains(pixel_x, pixel_y));
page5_btn.press(down && page5_btn.contains(pixel_x, pixel_y));
page6_btn.press(down && page6_btn.contains(pixel_x, pixel_y));
if (page1_btn.justReleased())
page1_btn.drawButton();
if (page2_btn.justReleased())
page2_btn.drawButton();
if (page3_btn.justReleased())
page3_btn.drawButton();
if (page4_btn.justReleased())
page4_btn.drawButton();
if (page5_btn.justReleased())
page5_btn.drawButton();
if (page6_btn.justReleased())
page6_btn.drawButton();
if (page1_btn.justPressed()) {
page1_btn.drawButton(true);
currentPage = INFO;
}
if (page2_btn.justPressed()) {
page2_btn.drawButton(true);
currentPage = BATTERIE;
}
if (page3_btn.justPressed()) {
page3_btn.drawButton(true);
currentPage = WATER;
}
if (page4_btn.justPressed()) {
page4_btn.drawButton(true);
currentPage = WETTER;
}
if (page5_btn.justPressed()) {
page5_btn.drawButton(true);
currentPage = SOLAR;
}
if (page6_btn.justPressed()) {
page6_btn.drawButton(true);
currentPage = ALARM;
}
break;
case WATER: //Wasserstand
if (currentPage != oldPage) drawWaterScreen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed())
{
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case SOLAR: //Solar 160W
if (currentPage != oldPage) drawSolarScreen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
next_btn.press(down && next_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (next_btn.justReleased())
next_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
if (next_btn.justPressed()) {
next_btn.drawButton(true);
currentPage = SOLAR1;
}
break;
case SOLAR1: //Solar 200 W
if (currentPage != oldPage) drawSolar1Screen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
next_btn.press(down && next_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (next_btn.justReleased())
next_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
if (next_btn.justPressed()) {
next_btn.drawButton(true);
currentPage = SOLAR2;
}
break;
case SOLAR2: //Batterie
if (currentPage != oldPage) drawSolar2Screen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case ALARM: //Wasserstand
if (currentPage != oldPage) drawAlarmScreen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed())
{
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case WETTER:
if (currentPage != oldPage) drawWetterScreen();
static uint32_t sekundenloop;
getUhrzeit();
updateUhrzeit();
getTemperatur();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed())
{
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case INFO:
if (currentPage != oldPage) drawInfoScreen();
if (Touch_getXY()) {
currentPage = MENU;
}
break;
case BATTERIE:
if (currentPage != oldPage) drawBatterieScreen();
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed())
{
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
case REALALARM: //Alarmanlage
if (currentPage != oldPage) drawRealAlarmScreen();
// draw0Gauge(tft.width() / 2, tft.height() / 2, 75);
menu_btn.press(down && menu_btn.contains(pixel_x, pixel_y));
info_btn.press(down && info_btn.contains(pixel_x, pixel_y));
if (menu_btn.justReleased())
menu_btn.drawButton();
if (menu_btn.justPressed()) {
menu_btn.drawButton(true);
currentPage = MENU;
}
break;
}
if (oldPage == currentPage) {
down = Touch_getXY();
} else {
down = false;
}
}
/************************************************************************************
SCREENS DEFINTION
************************************************************************************/
void drawMenuScreen() {
tft.fillScreen(BLACK);
tft.setTextColor(GREEN);
// Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "WoMo-Monitor", GREEN);
//tft.setFont(&FreeSmallFont);
tft.setTextSize(2);
tft.drawLine(0, 34, tft.width() * 0.6, 34, DARKGREEN); // Draws the red line
tft.setTextColor(WHITE, BLACK);//((255, 255, 255), (0,0,0));
tft.setCursor(0, 80);
tft.setTextColor(GREEN, BLACK);//((255, 255, 255), (0,0,0));
// Button
tft.drawRGBBitmap(448 - 16, 10, INFOICON, 32, 32);
tft.setFont(NULL);
page3_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), 130, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Wasser", 2);
page1_btn.initButton(&tft, 448, 26, 32, 32, WHITE, BLACK, BLACK, "", 2);
page2_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), (130 + btnHeight + margin), 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Batterie", 2);
page4_btn.initButton(&tft, (tft.width() / 2) + (btnWidth) + (margin / 2), (130 + btnHeight + margin), 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Wetter", 2);
page5_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), (130 + btnHeight * 2) + margin * 2, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Solar", 2);
page6_btn.initButton(&tft, (tft.width() / 2) + (btnWidth) + (margin / 2), (130 + btnHeight * 2) + margin * 2, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Alarm", 2);
page1_btn.drawButton(false);
page2_btn.drawButton(false);
page3_btn.drawButton(false);
page4_btn.drawButton(false);
page5_btn.drawButton(false);
page6_btn.drawButton(false);
//Button frame
tft.drawRoundRect(3, tft.height() / 2. - (1.5 * btnHeight + 2 * margin), tft.width() - 3, 4 * btnHeight + 5 * margin, 10, GREEN);
oldPage = currentPage;
}
void drawRealAlarmScreen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
tft.setTextSize(3);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(tft.width() / 2. - 9 * 3 * 3, 50);
tft.print("Du wolltest es so");
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_D4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_B3, 500);
delay(500); //1
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_D4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_B3, 500);
delay(500);//2
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_D5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_D5, 125);
delay(250);
tone(tonPin, NOTE_C5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_C5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_G4, 125);
delay(250);
tone(tonPin, NOTE_B4, 500);
delay(1000);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_D4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_B3, 500);
delay(500); //1
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_D4, 125);
delay(250);
tone(tonPin, NOTE_FS4, 125);
delay(250);
tone(tonPin, NOTE_B3, 500);
delay(500);//2
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_D5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_D5, 125);
delay(250);
tone(tonPin, NOTE_C5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_C5, 125);
delay(250);
tone(tonPin, NOTE_CS5, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_B4, 125);
delay(250);
tone(tonPin, NOTE_A4, 125);
delay(250);
tone(tonPin, NOTE_G4, 125);
delay(250);
tone(tonPin, NOTE_B4, 500);
delay(500);
}
void drawBatterieScreen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Ladezustand Batterien", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
tft.setFont(NULL);
//Aufbaubatterie
getAufbaubatterie();
getBordbatterie();
int radius = 70;
showmsgXY(48, 70, 1, &FreeSerif12pt7b, "Aufbaubatterie", CYAN);
tft.setCursor(80, 167);
tft.print(Aufbaubatterie / 100);
showmsgXY(140, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(Aufbaubatterie, 1180, 1480, 120 - radius, 160 - radius, radius, RED2GREEN);
//Bordbatterie
showmsgXY(298, 70, 1, &FreeSerif12pt7b, "Bordbatterie", CYAN);
tft.setCursor(320, 167);
tft.print(Bordbatterie / 100);
showmsgXY(380, 167, 1, &FreeSerif12pt7b, " V", CYAN);
radius = 70;
ringMeter(Bordbatterie, 1200, 1400, 360 - radius, 160 - radius, radius, RED2GREEN);
tft.setFont(NULL);
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
}
void drawSolarScreen()//Solar gesamt
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Solarleistung gesamt", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
getSolarVolts();
getSolarAmps();
getSolarAmps2();
getSolarWatts();
int radius = 70;
//Volts
tft.setCursor(50, 167);
tft.print(SolarVolts / 100);
showmsgXY(110, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(SolarVolts, 1200, 3600, 120 - radius - 30, 160 - radius, radius, RED2GREEN);
//Amps
tft.setCursor(200, 167);
tft.print(SolarAmps / 100 + SolarAmps2 / 100);
showmsgXY(260, 167, 1, &FreeSerif12pt7b, " A", CYAN);
ringMeter(SolarAmps, 100, 3000, 240 - radius, 160 - radius, radius, RED2GREEN);
//Watts
tft.setCursor(362, 167);
tft.print(SolarWatts);
showmsgXY(398, 167, 1, &FreeSerif12pt7b, " W", CYAN);
ringMeter(SolarWatts, 1, 400, 360 - radius + 30, 160 - radius , radius, RED2GREEN);
Serial.println("Solar V,A,W");
Serial.println(SolarVolts);
Serial.println(SolarAmps);
Serial.println(SolarWatts);
tft.setFont(NULL);
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
next_btn.initButton(&tft, tft.width() / 2. + btnWidth + margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "->", 2);
menu_btn.drawButton(false);
next_btn.drawButton(false);
oldPage = currentPage;
}
void drawSolar1Screen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Solarleistung", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
tft.setFont(NULL);
//Aufbaubatterie
getSolarVolts();
getSolarAmps();
getBatVolts();
getBatAmps();
int radius = 35;
showmsgXY(72, 70, 1, &FreeSerif12pt7b, "Von Solar", CYAN);
tft.setCursor(80, 167);
tft.print(SolarVolts / 100);
showmsgXY(140, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(Aufbaubatterie, 1180, 1480, 120 - radius, 160 - radius - 40, radius, RED2GREEN);
//Bordbatterie
showmsgXY(298, 70, 1, &FreeSerif12pt7b, "Zur Batterie", CYAN);
tft.setCursor(320, 167);
tft.print(Bordbatterie / 100);
showmsgXY(380, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(Bordbatterie, 1200, 1400, 360 - radius, 160 - radius - 40, radius, RED2GREEN);
ringMeter(Aufbaubatterie, 1180, 1480, 120 - radius, 160 + radius , radius, RED2GREEN);
ringMeter(Aufbaubatterie, 1180, 1480, 360 - radius, 160 + radius , radius, RED2GREEN);
tft.setFont(NULL);
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
next_btn.initButton(&tft, tft.width() / 2. + btnWidth + margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "->", 2);
menu_btn.drawButton(false);
next_btn.drawButton(false);
oldPage = currentPage;
}
void drawSolar2Screen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Solarleistung", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
tft.setFont(NULL);
//Aufbaubatterie
getSolarVolts();
getSolarAmps();
getBatVolts();
getBatAmps();
int radius = 35;
showmsgXY(72, 70, 1, &FreeSerif12pt7b, "Von Solar", CYAN);
tft.setCursor(80, 167);
tft.print(Aufbaubatterie / 100);
showmsgXY(140, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(Aufbaubatterie, 1180, 1480, 120 - radius, 160 - radius - 40, radius, RED2GREEN);
//Bordbatterie
showmsgXY(298, 70, 1, &FreeSerif12pt7b, "Zur Batterie", CYAN);
tft.setCursor(320, 167);
tft.print(Bordbatterie / 100);
showmsgXY(380, 167, 1, &FreeSerif12pt7b, " V", CYAN);
ringMeter(Bordbatterie, 1200, 1400, 360 - radius, 160 - radius - 40, radius, RED2GREEN);
ringMeter(Aufbaubatterie, 1180, 1480, 120 - radius, 160 + radius , radius, RED2GREEN);
ringMeter(Aufbaubatterie, 1180, 1480, 360 - radius, 160 + radius , radius, RED2GREEN);
tft.setFont(NULL);
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
}
void drawWaterScreen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Frischwasser", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
tft.setFont(NULL);
getWasser();
int radius = 100;
ringMeter(Wasserstand, 0, 100, 240 - radius, 160 - radius, radius, RED2GREEN);
if (Wasserstand > 99)
{
tft.setCursor(210, 152);
tft.setTextSize(2);
tft.print(Wasserstand);
tft.print(" %");
}
else
{
tft.setCursor(222, 152);
tft.setTextSize(2);
tft.print(Wasserstand);
tft.print(" %");
}
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
}
void drawAlarmScreen()
{
tft.setRotation(rotar);
tft.fillScreen(BLACK);
//Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "Frischwasser", CYAN);
tft.drawLine(0, 34, tft.width() * 0.6, 34, CYAN); // Draws the red line
tft.setFont(NULL);
getWasser();
int radius = 100;
ringMeter(Wasserstand, 0, 100, 240 - radius, 160 - radius, radius, RED2GREEN);
if (Wasserstand > 99)
{
tft.setCursor(210, 152);
tft.setTextSize(2);
tft.print(Wasserstand);
tft.print(" %");
}
else
{
tft.setCursor(222, 152);
tft.setTextSize(2);
tft.print(Wasserstand);
tft.print(" %");
}
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
}
void drawInfoScreen() {
tft.setRotation(rotar);
tft.fillScreen(BLACK);//(100, 155, 203)
tft.drawRoundRect(10, 50, tft.width() - 20, tft.height() - 60, 5, GREEN); //tft.fillRect (10, 10, 60, 36);
tft.setFont(NULL);
tft.setTextColor(WHITE);
tft.setCursor(25, 30);
tft.write("Informationen ");
tft.write(0x81);
tft.write("ber das System");
tft.setCursor(25, 80);
tft.write("Dieses System wurde in m");
tft.write(0x81);
tft.write("hevoller");
tft.setCursor(25, 105);
tft.write("Kleinstarbeit und mit viel Zeit");
tft.setCursor(25, 130);
tft.write("von Roland zusammengekl");
tft.write(0x94);
tft.write("ppelt.");
tft.setCursor(25, 155);
tft.write("Bei Fragen gerne melden.");
tft.setCursor(25, 205);
tft.write("Tel: +41 79 XXX XX XX");
tft.setCursor(25, 230);
tft.write("email: rxxxxxxxxx@gmail.com");
tft.setCursor(25, 280);
tft.write("Programmversion: 0.1");
tft.write(0xE0);
tft.setFont(NULL);
oldPage = currentPage;
}
void drawWetterScreen() {
tft.setRotation(rotar);
tft.fillScreen(BLACK);//(100, 155, 203)
menu_btn.initButton(&tft, tft.width() / 2. - btnWidth - margin, tft.height() - btnHeight / 2., btnWidth, btnHeight, WHITE, GREY, BLACK, "MENU", 2);
menu_btn.drawButton(false);
oldPage = currentPage;
tft.setTextColor(GREEN);
tft.setCursor(85, 250);
tft.write("Bitte etwas l");
tft.write(0x84);
tft.write("nger dr");
tft.write(0x81);
tft.write("cken");
tft.setFont(NULL);
}
/************************************************************************************
Zusätzliche Funktionen
*************************************************************************************/
bool Touch_getXY(void)
{
p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH);
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
if (tft.width() <= tft.height()) { //Portrait
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
} else {
pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
}
}
return pressed;
}
void getUhrzeit()
{
DateTime now = rtc.now(); //Daten auslesen
char buf1[] = " DDD"; //Wochentag in buf2[] schreiben
Tagnow = (now.toString(buf1)); //Wochentag als String übergeben an tagnow
//Überprüfung welcher Wochentag ist, und diesen dann ausgeschrieben an Display senden mit Zeilenumbruch
if (Tagnow == " Sam") Wochentag = "Samstag";
else if (Tagnow == " Son") Wochentag = "Sonntag";
else if (Tagnow == " Mon") Wochentag = "Montag";
else if (Tagnow == " Die") Wochentag = "Dienstag";
else if (Tagnow == " Mit") Wochentag = "Mittwoch";
else if (Tagnow == " Don") Wochentag = "Donnerstag";
else if (Tagnow == " Fre") Wochentag = "Freitag";
//Überprüfung fertig
char buf2[] = "DD.MM.YYYY";
Datumget = (now.toString(buf2));
char buf3[] = "hh:mm:ss";
Uhrget = (now.toString(buf3)); //Aktuelle Uhrzeit in oledreset schreiben
}
void updateUhrzeit()
{
if (Uhrget != Uhrget_alt or Datumget != Datumget_alt or Tagnow != Tagnow_alt) {
Serial.println("void UpdateUhrzeit");
tft.setTextColor(GREEN, BLACK);
tft.setTextSize(2);
tft.setCursor(50, 50);
tft.print("Heute ist:");
tft.setCursor(261, 50);
tft.print(Wochentag);
Serial.println(Wochentag);
Serial.println(Tagnow);
tft.setCursor(261, 75);
tft.print(Datumget);
Serial.println(Datumget);
tft.setCursor(261, 100);
tft.print(Uhrget);
Serial.println(Uhrget);
Uhrget = Uhrget_alt;
Datumget = Datumget_alt;
Tagnow = Tagnow_alt;
}
}
void getTemperatur()
{
// Temperaturmessung dht
h = dht.readHumidity(); //Feuchtigkeit messen
t = dht.readTemperature(); //Temperatur in Celsius messen
if (isnan(h) || isnan(t)) { //testen, ob eine Messung fehlschlug
Serial.println(F("DHT Sensor konnte nicht messen"));
return; //zurück
}
if (h != h_alt or t != t_alt) {
Serial.println("void getTemperatur");
tft.setTextColor(GREEN, BLACK);
tft.setTextSize(2);
tft.setCursor(50, 150);
tft.print("Temperatur: ");
tft.setCursor(261, 150);
tft.print(t, 1);
tft.write(0xF7);
tft.write("C");
tft.setCursor(50, 175);
tft.print("Luftfeuchtigkeit: ");
tft.setCursor(261, 175);
tft.print(h, 1);
tft.write("%");
h = h_alt;
t = t_alt;
}
}
void getWasser()
{
randomSeed(millis());
Wasserstand = random(10, 100);
Serial.println(Wasserstand);
}
void getSolarVolts()
{
randomSeed(millis());
SolarVolts = random(1200, 3600);
}
void getSolarAmps()
{
randomSeed(millis());
SolarAmps = random(100, 1500);
}
void getSolarAmps2()
{
randomSeed(millis());
SolarAmps = random(100, 1500);
}
void getSolarWatts()
{
SolarWatts = SolarVolts / 100 * (SolarAmps / 100 + SolarAmps2 / 100);
}
void getBatVolts()
{
randomSeed(millis());
BatVolts = random(1200, 1500);
}
void getBatAmps()
{
randomSeed(millis());
BatAmps = random(100, 150);
}
void getAufbaubatterie()
{
randomSeed(millis());
Aufbaubatterie = random(1180, 1480);
Serial.println("Aufbaubatterie: " + String(Aufbaubatterie));
}
void getBordbatterie()
{
randomSeed(millis());
Bordbatterie = random(1200, 1400);
Serial.println("Bordbatterie: " + String(Bordbatterie));
}
void showmsgXY(int x, int y, int sz, const GFXfont * f, const char *msg, char *Farbe)
{
int16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(Farbe);
tft.setTextSize(sz);
tft.print(msg);
}
//Gauge
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, byte scheme)
{
// Minimum value of r is about 52 before value text intrudes on ring
// drawing the text first is an option
x += r; y += r; // Calculate coords of centre of ring
int w = r / 4; // Width of outer ring is 1/4 of radius
int angle = 150; // Half the sweep angle of meter (300 degrees)
int text_colour = 0; // To hold the text colour
int v = map(value, vmin, vmax, -angle, angle); // Map the value to an angle v
byte seg = 5; // Segments are 5 degrees wide = 60 segments for 300 degrees
byte inc = 10; // Draw segments every 5 degrees, increase to 10 for segmented ring
// Draw colour blocks every inc degrees
for (int i = -angle; i < angle; i += inc) {
// Choose colour from scheme
int colour = 0;
switch (scheme) {
case 0: colour = RED; break; // Fixed colour
case 1: colour = GREEN; break; // Fixed colour
case 2: colour = BLUE; break; // Fixed colour
case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break; // Full spectrum blue to red
case 4: colour = rainbow(map(i, -angle, angle, 63, 127)); break; // Green to red (high temperature etc)
case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // Red to green (low battery etc)
default: colour = BLUE; break; // Fixed colour
}
// Calculate pair of coordinates for segment start
float sx = cos((i - 90) * 0.0174532925);
float sy = sin((i - 90) * 0.0174532925);
uint16_t x0 = sx * (r - w) + x;
uint16_t y0 = sy * (r - w) + y;
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
// Calculate pair of coordinates for segment end
float sx2 = cos((i + seg - 90) * 0.0174532925);
float sy2 = sin((i + seg - 90) * 0.0174532925);
int x2 = sx2 * (r - w) + x;
int y2 = sy2 * (r - w) + y;
int x3 = sx2 * r + x;
int y3 = sy2 * r + y;
if (i < v) { // Fill in coloured segments with 2 triangles
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
text_colour = colour; // Save the last colour drawn
}
else // Fill in blank segments
{
tft.fillTriangle(x0, y0, x1, y1, x2, y2, DARKGREY);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, DARKGREY);
}
}
}
// #########################################################################
// Return a 16 bit rainbow colour
// #########################################################################
unsigned int rainbow(byte value)
{
// Value is expected to be in range 0-127
// The value is converted to a spectrum colour from 0 = blue through to 127 = red
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
//Ende Gauge
pitches.h (2,0 KB)
icons.h (9,9 KB)
eigentlich geht es nur um den folgenden Codeabschnitt wo das menu gezeichnet wird.
Ich weiss, der Sketch sieht noch etwas wirr aus, aber aufgeräumt wird später.
void drawMenuScreen() {
tft.fillScreen(BLACK);
tft.setTextColor(GREEN);
// Title
showmsgXY(20, 30, 1, &FreeSerif12pt7b, "WoMo-Monitor", GREEN);
//tft.setFont(&FreeSmallFont);
tft.setTextSize(2);
tft.drawLine(0, 34, tft.width() * 0.6, 34, DARKGREEN); // Draws the red line
tft.setTextColor(WHITE, BLACK);//((255, 255, 255), (0,0,0));
tft.setCursor(0, 80);
tft.setTextColor(GREEN, BLACK);//((255, 255, 255), (0,0,0));
// Button
tft.drawRGBBitmap(448 - 16, 10, INFOICON, 32, 32);
tft.setFont(NULL);
page3_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), 130, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Wasser", 2);
page1_btn.initButton(&tft, 448, 26, 32, 32, WHITE, BLACK, BLACK, "", 2);
page2_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), (130 + btnHeight + margin), 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Batterie", 2);
page4_btn.initButton(&tft, (tft.width() / 2) + (btnWidth) + (margin / 2), (130 + btnHeight + margin), 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Wetter", 2);
page5_btn.initButton(&tft, (tft.width() / 2) - (btnWidth) - (margin / 2), (130 + btnHeight * 2) + margin * 2, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Solar", 2);
page6_btn.initButton(&tft, (tft.width() / 2) + (btnWidth) + (margin / 2), (130 + btnHeight * 2) + margin * 2, 2 * btnWidth, btnHeight, WHITE, GREEN, BLACK, "Alarm", 2);
page1_btn.drawButton(false);
page2_btn.drawButton(false);
page3_btn.drawButton(false);
page4_btn.drawButton(false);
page5_btn.drawButton(false);
page6_btn.drawButton(false);
//Button frame
tft.drawRoundRect(3, tft.height() / 2. - (1.5 * btnHeight + 2 * margin), tft.width() - 3, 4 * btnHeight + 5 * margin, 10, GREEN);
oldPage = currentPage;
}
Hat jemand eine Idee?