Hallo zusammen!
Ich habe mir das Elegoo 2.8" TFT Display Shield gekauft, nun möchte ich per Touch eine LED-Kette steuern.
Zuerst habe einen Art Hauptbildschirm erstellt auf dem Knöpfe (zurzeit nur einer) angezeigt werden sollen. Nun folgt mein Problem, nachdem ich den ersten Knopf erstellt habe und ihn nun per Touch in öffnen möchte. Das erstellen des Knopfes hat einwandfrei funktioniert, jedoch ist der Bereich in dem der Knopf beim Touch erkennt wird, wo anders am Display platziert. Ich habe mehrere Bibliotheken und vor allem sehr viele Möglichkeiten die x- und y-Werte des TFT zu konfigurieren. Nun meine Frage: Gibt es eine Möglichkeit den Bereich in dem der Touch den Knopf erkennt zu verschieben sodass, wenn ich Knöpfe hinzufügen möchte, bei diesen auch Anwenden kann? ACHTUNG: Code kann etwas verwirrend sein, da er noch nicht fertig ist.
Vielen Dank im vorraus!
// IMPORTANT: ELEGOO_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Elegoo_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
//Touch For New ILI9341 TP
#define TS_MINX 150
#define TS_MAXX 3800
#define TS_MINY 130
#define TS_MAXY 4000
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Elegoo_TFTLCD tft;
char currentPage, selectedUnit;
int x, y;
// RGB LEDs
const int redLed = 10;
const int greenLed = 9;
const int blueLed = 8;
int xR = 38;
int xG = 38;
int xB = 38;
Elegoo_GFX_Button button;
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void setup() {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_Elegoo_SHIELD_PINOUT
Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
if (identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if (identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if (identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
} else if (identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if (identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if (identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if (identifier == 0x0101)
{
identifier = 0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
identifier = 0x9341;
}
tft.begin(identifier);
tft.setRotation(1);
Serial.print(F("setting Homescreen... "));
Serial.println(drawHomescreen(RED, WHITE));
currentPage = '0';
selectedUnit = '0';
button.initButton(&tft, 160, 70, 165, 25, WHITE, WHITE, RED, "LED's", 2);
button.drawButton();
}
void loop() {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = (tft.height()-map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
}
p.y = tft.height() - p.x;
p.x = p.y;
// if sharing pins, you'll need to fix the directions of the touchscreen pins
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
if (currentPage = '0') {
if(button.contains(p.x, p.y)){
button.press(true);
Serial.print("Pressed, X: "); Serial.print(p.x); Serial.print(", Y: "); Serial.print(p.y); Serial.println();
}else{
// Serial.print("Not Pressed, X: "); Serial.print(p.x); Serial.print(", Y: "); Serial.print(p.y); Serial.println();
button.press(false);
}
}
}
unsigned long drawHomescreen(uint16_t color1, uint16_t color2) {
tft.fillScreen(BLACK);
tft.drawRect(65, 20, 187, 30, color2);
tft.fillRect(66, 21, 185, 28, color1);
tft.setTextColor(MAGENTA);
tft.setTextSize(3);
tft.setCursor(70, 25);
tft.println("Homescreen");
/* tft.drawRect(75, 70, 165, 25, color2);
tft.fillRect(76, 71, 163, 23, color1);
tft.setTextColor(MAGENTA);
tft.setTextSize(2);
tft.setCursor(80, 75);
tft.println("LED Steuerung");*/
}
//RGB LED CONTROL
unsigned long drawLEDControl () {
tft.setCursor(0,0);
tft.setTextColor(WHITE);
tft.println("READY");
}