Funktioniert leider auch nicht.
Das Relais Schaltet nicht ein.
Hier mal der Komplette Code:
#include <UTFT.h>
#include <URTouch.h>
UTFT myGLCD(SSD1289,38,39,40,41);
URTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
int x, y;
int VddRelais = 17;
char currentPage, selectedUnit;
unsigned long R1_timestore;
const int relais1 = 8;
int staterelais1 = HIGH;
// ====== Custom Funtions ======
// drawHomeScreen - Custom Function
void drawHomeScreen() {
// Title
//myGLCD.setBackColor(0,0,0); // Sets the background color of the area where the text will be printed to black
myGLCD.setColor(255, 255, 255); // Sets color to white
myGLCD.setFont(BigFont); // Sets font to big
myGLCD.print("LegoCity Weichen", CENTER, 10); // Prints the string on the screen
myGLCD.setColor(255, 0, 0); // Sets color to red
myGLCD.drawLine(0,32,319,32); // Draws the red line
// Button - WEICHE 1
myGLCD.setColor(16, 167, 103);
myGLCD.fillRoundRect (20, 40, 150, 80);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (20, 40, 150, 80);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(16, 167, 103);
myGLCD.print("WEICHE 1", 21, 52);
}
// Highlights the button when pressed
void drawRoundRect(int x1, int y1, int x2, int y2) {
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
digitalWrite(relais1,HIGH);
pinMode(relais1, OUTPUT);
pinMode(VddRelais, OUTPUT);
digitalWrite(VddRelais, HIGH);
drawHomeScreen(); // Draws the Home Screen
currentPage = '0'; // Indicates that we are at Home Screen
}
void loop() {
if (currentPage == '0') {
if (myTouch.dataAvailable()) {
myTouch.read();
x=myTouch.getX(); // X coordinate where the screen has been pressed
y=myTouch.getY(); // Y coordinates where the screen has been pressed
// If we press "WEICHE X"
if ((x>=20) && (x<=150) && (y>=40) && (y<=80)) {
drawRoundRect(20, 40, 150, 80);
R1_timestore = millis();
if(staterelais1 == LOW){
staterelais1 = HIGH;
// delay(100);
digitalWrite(relais1,staterelais1);
}
else {
if (millis() - R1_timestore > 5000) {
staterelais1 = LOW;
digitalWrite(relais1,staterelais1);
}
}
}
}
}
}