hello
i need help with this sketch
i work with the uno
2,8 tft with touchscreen
and an 4 relays board
al of this works with this sketch but the relay is not stabil in his contact i want to control the relay with the touch as an pushbutton when i push relay on and off as i the screen not touch
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#define YP A1
#define XM A2
#define YM 7
#define XP 6
#define MINPRESSURE 1
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
short TS_MINX = 150;
short TS_MINY = 120;
short TS_MAXX = 850;
short TS_MAXY = 891;
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int X;
int Y;
int Z;
int a = 0;
#define BOXSIZE 110
#define PENRADIUS 3
int oldcolor, currentcolor;
#define vooromhoog 10
void setup(void)
{
tft.begin(0x9341);
pinMode(10, OUTPUT);
tft.fillScreen(BLACK);//BG COLOR
}
void loop()
{
lecturaPanel(); // Realizamos lectura del panel para detectar presion y coordenadas
// Si la pulsación del eje X se produce entre los puntos 40 y 160
// Y la pulsacion del eje Y se produce entre los puntos 20 y 60
// Y la presión realizada esta entre el margen determinado
if((X > 20 && X < 400) && (Y > 20 && Y < 60) && (Z > MINPRESSURE && Z < MAXPRESSURE))
{
digitalWrite(vooromhoog, LOW);
delay(20);
digitalWrite(vooromhoog, HIGH);
}
}
void lecturaPanel()
{
TSPoint p = ts.getPoint(); // Realizamos lectura de las coordenadas
pinMode(XM, OUTPUT); // La librería utiliza estos pines como entrada y salida
pinMode(YP, OUTPUT); // por lo que es necesario declararlos como salida justo
// despues de realizar una lectura de coordenadas.
// Mapeamos los valores analogicos leidos del panel tactil (0-1023)
// y los convertimos en valor correspondiente a la medida del LCD 320x240
X = map(p.x, TS_MAXX, TS_MINX, tft.width(), 0);
Y = map(p.y, TS_MAXY, TS_MINY, tft.height(), 0);
Z = p.z;
}
im from the netherlands