Hello good people out there..
First thing first .. thank you for the asume and helpsome comunity .. though i havent realy used it before and this be the first time i love it is intelegents and healtyness i have very limited knowledge about programming in general so i kind of need help with even the basics ..
and by the way sorry for my spelling mistakes..
I am her seeking help with a very simple arduino projet, making 6 relays work with arduino touch interface,
3 of them individually and
3 of them where they chacel eachother..
I have modified a sketch come across online among the 100 others i have tried it and it seems like it has good potentials even for a nobi like me :-S .. and talking about the skech thanks upfront to the orginal creater of the sketch and all other pople involved in the libarys and more..
I am using a touchscreen that seems to be mirrored in the touch functions or something .. so it makes things even more complicated for a greeny me !"
I will appreciate if somone could help me with either this or similar button interface, that actuely works with my shield..
I have a made a video showing how the interface and how it reacts now.. and her is the code
//Programa : Teste Display Touch Arduino - Touchscreen
//Autor : FILIPEFLOP
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#define YP A1 // Y+ is on Analog1 (use A3 para o 9341)
#define XM A2 // X- is on Analog2 (use A2 para o 9341)
#define YM 7 // Y- is on Digital7 (use 9 para o 9341)
#define XP 6 // X+ is on Digital6 (use 8 para o 9341)
#define TS_MINX 40 // Use 150 para o 9341
#define TS_MINY 100 // Use 120 para o 9341
#define TS_MAXX 780
#define TS_MAXY 135
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 100);
//Definicao de cores
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//PP_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
// Armazena o estado dos botões
bool valor_botao1 = 0;
bool valor_botao2 = 0;
bool valor_botao3 = 0;
bool valor_botao4 = 0;
bool valor_botao5 = 0;
#define MINPRESSURE 5
#define MAXPRESSURE 1000
void setup(void)
{
Serial.begin(9600);
Serial.println("TFT Test");
//identifier == 0x9325;
tft.reset();
delay(500);
//uint16_t identifier = tft.readID(0x0);
//Serial.print("Driver encontrado: ");
//Serial.println(identifier, HEX);
tft.begin(0x9341); //Use esta linha para o controlador 9341
//tft.begin(0x9325);
//tft.initDisplay();
tft.fillScreen(BLACK);
tft.setRotation(2);
// Inicio - Texto e botoes
//button 1
tft.drawRoundRect(75, 25, 160, 50, 50, WHITE); //big box
tft.drawRoundRect(5, 25, 62, 50, 50, WHITE); // smal box
tft.setTextColor(YELLOW); //Color
tft.setTextSize(2); //text size
tft.setCursor(135, 42); //Box number position
tft.println("1"); //Box Number
//Button 2
tft.drawRoundRect(75, 85, 160, 50, 50, WHITE);
tft.drawRoundRect(5, 85, 62, 50, 50, WHITE);
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.setCursor(135, 102);
tft.println("2");
//Button 3
tft.drawRoundRect(75, 145, 160, 50, 50, WHITE);
tft.drawRoundRect(5, 145, 62, 50, 50, WHITE);
tft.setTextColor(BLUE);
tft.setTextSize(2);
tft.setCursor(135, 162);
tft.println("3");
//Button 4
tft.drawRoundRect(75, 205, 160, 50, 50, WHITE);
tft.drawRoundRect(5, 205, 62, 50, 50, WHITE);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.setCursor(135, 222);
tft.println("4");
//Button 5
tft.drawRoundRect(75, 265, 160, 50, 50, WHITE);
tft.drawRoundRect(5, 265, 62, 50, 50, WHITE);
tft.setTextColor(CYAN);
tft.setTextSize(2);
tft.setCursor(135, 282);
tft.println("5");
//Preenchimento OFF -OFF Buttons text positioning
tft.setTextColor(WHITE);
tft.setCursor(20, 44);
tft.println("OFF");
tft.setCursor(20, 104);
tft.println("OFF");
tft.setCursor(20, 164);
tft.println("OFF");
tft.setCursor(20, 224);
tft.println("OFF");
tft.setCursor(20, 284);
tft.println("OFF");
}
void loop()
{
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
digitalWrite(XM, LOW);
pinMode(YP, OUTPUT);
digitalWrite(YP, HIGH);
pinMode(YM, OUTPUT);
digitalWrite(YM, LOW);
pinMode(XP, OUTPUT);
digitalWrite(XP, HIGH);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
{
p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
if (p.y > 200)
{
Serial.print("py: ");
Serial.print(p.y);
Serial.print(" px: ");
Serial.print(p.x);
//B1
if (p.x > 235 & p.x < 295)
{
if (valor_botao1 == 0)
{
tft.fillRoundRect(5, 25, 62, 50, 50, YELLOW);
mostra_on(20, 44);
valor_botao1 = !valor_botao1;
}
else
{
tft.fillRoundRect(5, 25, 62, 50, 50, BLACK);
mostra_off(20, 44);
valor_botao1 = !valor_botao1;
}
}
//B2
if (p.x > 235 & p.x < 295)
{
if (valor_botao1 == 0)
{
tft.fillRoundRect(5, 85, 62, 50, 50, GREEN);
mostra_on(20, 104);
valor_botao2 = !valor_botao2;
}
else
{
tft.fillRoundRect(5, 85, 62, 50, 50, BLACK);
mostra_off(20, 104);
valor_botao2 = !valor_botao2;
}
}
//B3
if (p.x > 235 & p.x < 295)
{
if (valor_botao2 == 0)
{
tft.fillRoundRect(5, 145, 62, 50, 50, BLUE);
mostra_on(20, 164);
valor_botao3 = !valor_botao3;
}
else
{
tft.fillRoundRect(5, 145, 62, 50, 50, BLACK);
mostra_off(20, 164);
valor_botao3 = !valor_botao3;
}
}
//B4
if (p.x > 126 & p.x < 184)
{
if (valor_botao3 == 0)
{
tft.fillRoundRect(5, 205, 62, 50, 50, RED);
mostra_on(20, 224);
valor_botao4 = !valor_botao4;
}
else
{
tft.fillRoundRect(5, 205, 62, 50, 50, BLACK);
mostra_off(20, 224);
valor_botao4 = !valor_botao4;
}
}
//B5
if (p.x > 10 & p.x < 58)
{
if (valor_botao4 == 0)
{
tft.fillRoundRect(5, 265, 62, 50, 50, CYAN);
mostra_on(20,284);
valor_botao5 = !valor_botao5;
}
else
{
tft.fillRoundRect(5, 265, 62, 50, 50, BLACK);
mostra_off(20,284);
valor_botao5 = !valor_botao5;
}
}
}
}
}
void mostra_on(int y, int x)
{
tft.setTextColor(WHITE);
tft.setCursor(y, x);
tft.println("ON");
delay(100);
}
void mostra_off(int y, int x)
{
tft.setTextColor(WHITE);
tft.setCursor(y, x);
tft.println("OFF");
delay(100);
}
will appreciate any help.