Last active
October 30, 2023 18:46
-
-
Save maxpromer/fd67ceddfa7f5d7ae910fb81e38ff5c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TFT_eSPI.h> | |
#include <FT6336U.h> | |
TFT_eSPI tft = TFT_eSPI(); | |
FT6336U tp; | |
void setup() { | |
Serial.begin(115200); | |
pinMode(14, OUTPUT); | |
tft.init(); | |
tft.setRotation(1); | |
tft.invertDisplay(true); | |
tp.begin(); | |
tft.fillScreen(tft.color24to16(0xFFFFFF)); | |
tft.fillCircle(100, 100, 60, tft.color24to16(0xC3C3C3)); | |
tft.fillRect(0, 200, 240, 120, tft.color24to16(0x1ABC9C)); | |
tft.fillRect(240, 200, 240, 120, tft.color24to16(0xE74C3C)); | |
tft.setTextSize(6); | |
tft.setTextColor(tft.color24to16(0x3B3B3B)); | |
tft.setTextDatum(ML_DATUM); | |
tft.drawString("GPIO14", 200, 100); | |
tft.setTextSize(4); | |
tft.setTextColor(tft.color24to16(0xFFFFFF)); | |
tft.setTextDatum(MC_DATUM); | |
tft.drawString("ON", 120, 260); | |
tft.drawString("OFF", 360, 260); | |
} | |
void loop() { | |
if (tp.read_touch_number()) { | |
int y = tp.read_touch1_x(); | |
int x = tp.read_touch1_y(); | |
y = 320 - y; | |
Serial.printf("Touched at (%d, %d)\n", x, y); | |
if ((x > 0 && x < 240) && (y > 200 && y < 320)) { | |
digitalWrite(14, HIGH); | |
tft.fillCircle(100, 100, 60, tft.color24to16(0x27AE60)); | |
} else if ((x > 240 && x < 480) && (y > 200 && y < 320)) { | |
digitalWrite(14, LOW); | |
tft.fillCircle(100, 100, 60, tft.color24to16(0xC3C3C3)); | |
} | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment