hallo
jetzt hab ich alles soweit das es aussieht wie ich es haben möchte Touch und eine Relaiskarte die mir dann alles schaltet nur habe ich ein problem wie kann man die buttons auf den display genau positionieren denn zur zeit gehen alle relais zusammen an und aus die schrift passt nur die Push buttons anscheinen nicht könnt ihr mir da helfen
mein script:
#include <UTFT.h>
#include <ITDB02_Touch.h>
// Declare which fonts we will be using
extern uint8_t BigFont[];// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int Relais6 = 13;
int Relais5 = 12;
int Relais4 = 11;
int Relais3 = 10;
int Relais2 = 9;
int Relais1 = 8;
// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16); // Remember to change the model parameter to suit your display module!
//ITDB02_Touch myTouch(15,10,14,9,8);
// Uncomment the next line for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!
ITDB02_Touch myTouch(6,5,4,3,2);
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
void setup()
{
// Initial setup
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);
// initialize the digital pin as an output.
pinMode(Relais6, OUTPUT);
pinMode(Relais5, OUTPUT);
pinMode(Relais4, OUTPUT);
pinMode(Relais3, OUTPUT);
pinMode(Relais2, OUTPUT);
pinMode(Relais1, OUTPUT);
// Draw the upper row of buttons
for (x=0; x<8; x++);
{
myGLCD.setBackColor (0, 0, 255);
myGLCD.setColor(255, 255, 255);
myGLCD.print("BAD", 10, 20);
myGLCD.fillRoundRect (190, 15, 240, 40);
myGLCD.drawRoundRect (190, 15, 240, 40);
myGLCD.print("ON", 200, 20);
myGLCD.fillRoundRect (250, 15, 300, 40);
myGLCD.drawRoundRect (250, 15, 300, 40);
myGLCD.print("OFF", 250, 20);
myGLCD.print("KUECHE", 10, 60);
myGLCD.fillRoundRect (190, 55, 240, 80);
myGLCD.drawRoundRect (190, 55, 240, 80);
myGLCD.print("ON", 200, 60);
myGLCD.fillRoundRect (250, 55, 300, 80);
myGLCD.drawRoundRect (250, 55, 300, 80);
myGLCD.print("OFF", 250, 60);
myGLCD.print("WOHN", 10, 100);
myGLCD.fillRoundRect (190, 95, 240, 120);
myGLCD.drawRoundRect (190, 95, 240, 120);
myGLCD.print("ON", 200, 100);
myGLCD.fillRoundRect (250, 95, 300, 120);
myGLCD.drawRoundRect (250, 95, 300, 120);
myGLCD.print("OFF", 250, 100);
myGLCD.print("POOL", 10, 140);
myGLCD.fillRoundRect (190, 145, 240, 160);
myGLCD.drawRoundRect (190, 145, 240, 160);
myGLCD.print("ON", 200, 140);
myGLCD.fillRoundRect (250, 145, 300, 160);
myGLCD.drawRoundRect (250, 145, 300, 160);
myGLCD.print("OFF", 250, 140);
myGLCD.print("RADIO", 10, 180);
myGLCD.fillRoundRect (190, 195, 240, 200);
myGLCD.drawRoundRect (190, 195, 240, 200);
myGLCD.print("ON", 200, 180);
// myGLCD.fillRoundRect (190, 15, 240, 40);
// myGLCD.drawRoundRect (190, 15, 240, 40);
myGLCD.print("OFF", 250, 180);
myGLCD.print("LEER", 10, 220);
// myGLCD.fillRoundRect (190, 15, 240, 40);
// myGLCD.drawRoundRect (190, 15, 240, 40);
myGLCD.print("ON", 200, 220);
// myGLCD.fillRoundRect (190, 15, 240, 40);
// myGLCD.drawRoundRect (190, 15, 240, 40);
myGLCD.print("OFF", 250, 220);
}
//myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
//myGLCD.setColor(0, 0, 255);
//myGLCD.fillRoundRect (10, 130, 150, 180);
//myGLCD.setColor(255, 255, 255);
//myGLCD.drawRoundRect (10, 130, 150, 180);
//myGLCD.print("Clear", 40, 147);
//myGLCD.setColor(0, 0, 255);
//myGLCD.fillRoundRect (160, 130, 300, 180);
//myGLCD.setColor(255, 255, 255);
//myGLCD.drawRoundRect (160, 130, 300, 180);
//myGLCD.print("Enter", 190, 147);
//myGLCD.setBackColor (0, 0, 0);
}
void updateStr(int val)
{
if (stCurrentLen<20)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(0, 255, 0);
myGLCD.print(stCurrent, LEFT, 224);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}
// Draw a red frame while a button is touched
void waitForIt(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 loop()
{
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=15) && (y<=120)) // Upper row
{
if ((x>=190) && (x<=240)) // Button: Bad ON
digitalWrite(Relais1, LOW); // turn the LED on (HIGH is the voltage level)
{
waitForIt(190, 15, 240, 40);
}
if ((x>=250) && (x<=300)) // Button: Bad OFF
digitalWrite(Relais1, HIGH); // turn the LED on (HIGH is the voltage level)
{
waitForIt(250, 15, 300, 40);
if ((x>=190) && (x<=240)) // Button: Kueche ON
digitalWrite(Relais2, LOW); // turn the LED on (HIGH is the voltage level)
{
waitForIt(190, 55, 240, 80);
}
if ((x>=250) && (x<=300)) // Button: Kueche OFF
digitalWrite(Relais2, HIGH); // turn the LED on (HIGH is the voltage level)
{
waitForIt(250, 55, 300, 80);
}
if ((x>=190) && (x<=240)) // Button: Wohn ON
digitalWrite(Relais3, LOW); // turn the LED on (HIGH is the voltage level)
{
waitForIt(190, 95, 240, 120);
if ((x>=250) && (x<=300)) // Button: Wohn OFF
digitalWrite(Relais3, HIGH); // turn the LED on (HIGH is the voltage level)
{
waitForIt(250, 95, 300, 120);
}
if ((x>=190) && (x<=240)) // Button: POOL ON
digitalWrite(Relais4, LOW); // turn the LED on (HIGH is the voltage level)
{
waitForIt(190, 145, 240, 160);
}
if ((x>=250) && (x<=300)) // Button: POOL OFF
digitalWrite(Relais4, HIGH); // turn the LED on (HIGH is the voltage level)
{
waitForIt(250, 145, 300, 160);
}
if ((x>=190) && (x<=240)) // Button: Radio ON
digitalWrite(Relais5, LOW); // turn the LED on (HIGH is the voltage level)
{
waitForIt(190, 195, 240, 200);
}
if ((x>=250) && (x<=300)) // Button: Radio OFF
digitalWrite(Relais5, HIGH); // turn the LED on (HIGH is the voltage level)
{
waitForIt(250, 195, 300, 200);
}
}
//if ((y>=10) && (y<=180)) // Upper row
{
// if ((x>=10) && (x<=150)) // Button: Clear
{
// waitForIt(10, 130, 150, 180);
// stCurrent[0]='\0';
// stCurrentLen=0;
// myGLCD.setColor(0, 0, 0);
//myGLCD.fillRect(0, 224, 319, 239);
}
// if ((x>=160) && (x<=300)) // Button: Enter
{
// waitForIt(160, 130, 300, 180);
// if (stCurrentLen>0)
{
// for (x=0; x<stCurrentLen+1; x++)
{
// stLast[x]=stCurrent[x];
}
// stCurrent[0]='\0';
// stCurrentLen=0;
// myGLCD.setColor(0, 0, 0);
// myGLCD.fillRect(0, 208, 319, 239);
// myGLCD.setColor(0, 255, 0);
// myGLCD.print(stLast, LEFT, 208);
}
// else
{
//myGLCD.setColor(255, 0, 0);
//myGLCD.print("BUFFER EMPTY", CENTER, 192);
//delay(500);
//myGLCD.print(" ", CENTER, 192);
//delay(500);
//myGLCD.print("BUFFER EMPTY", CENTER, 192);
//delay(500);
//myGLCD.print(" ", CENTER, 192);
//myGLCD.setColor(0, 255, 0);
}
}
}
}
}
}
}
}
danke