From 250659ee12c07a3e9fb7f77c191afc017dd49e13 Mon Sep 17 00:00:00 2001 From: ESTninja Date: Sat, 25 Apr 2026 15:49:57 +0300 Subject: [PATCH 1/2] Add LED control functionality and integrate with command handling --- CYD/LED_Solution.cpp | 24 ++++++++++++++++++++++++ CYD/main.cpp | 8 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 CYD/LED_Solution.cpp diff --git a/CYD/LED_Solution.cpp b/CYD/LED_Solution.cpp new file mode 100644 index 0000000..60b8d02 --- /dev/null +++ b/CYD/LED_Solution.cpp @@ -0,0 +1,24 @@ +#include + +//pins for the RGB LED +const int LED_R = 4; +const int LED_G = 16; +const int LED_B = 17; + +void setLedColor(bool redOn, bool greenOn, bool blueOn) +{ + // active-low LED: + digitalWrite(LED_R, redOn ? LOW : HIGH); + digitalWrite(LED_G, greenOn ? LOW : HIGH); + digitalWrite(LED_B, blueOn ? LOW : HIGH); +} + +void setupLed() +{ + pinMode(LED_R, OUTPUT); + pinMode(LED_G, OUTPUT); + pinMode(LED_B, OUTPUT); + + // alguses kõik välja + setLedColor(false, false, false); +} \ No newline at end of file diff --git a/CYD/main.cpp b/CYD/main.cpp index e178e53..ab0fe3d 100644 --- a/CYD/main.cpp +++ b/CYD/main.cpp @@ -1,5 +1,6 @@ #include #include "AnimationPlayer.h" +#include "LED_Solution.h" void handleCommand(String cmd) { @@ -12,16 +13,19 @@ void handleCommand(String cmd) if (cmd == "caring") { switchFolder("/caring"); + setLedColor(true, false, false); Serial.println("Switched to /caring"); } else if (cmd == "surprised") { switchFolder("/surprised"); + setLedColor(false, false, true); Serial.println("Switched to /surprised"); } else if (cmd == "pride") { switchFolder("/pride"); + setLedColor(false, true, false); Serial.println("Switched to /pride"); } else @@ -33,8 +37,10 @@ void handleCommand(String cmd) void setup() { Serial.begin(115200); - used_to_be_setup(); + used_to_be_setup();//Edited setup from animationplayer. + setupLed(); switchFolder("/pride"); + Serial.println("Ready for UART commands"); From 7858e9f04929fad0d8b49a0036770ca4cd8def5e Mon Sep 17 00:00:00 2001 From: ESTninja Date: Sat, 25 Apr 2026 18:57:58 +0300 Subject: [PATCH 2/2] Tried to get cordinates from touch screen. Unfinished. --- CYD/TouchHandler.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ CYD/main.cpp | 19 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 CYD/TouchHandler.cpp diff --git a/CYD/TouchHandler.cpp b/CYD/TouchHandler.cpp new file mode 100644 index 0000000..99210d7 --- /dev/null +++ b/CYD/TouchHandler.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include "TouchHandler.h" + +#define TOUCH_IRQ 36 +#define TOUCH_MOSI 32 +#define TOUCH_MISO 39 +#define TOUCH_CLK 25 +#define TOUCH_CS 33 + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + +XPT2046_Touchscreen touchscreen(TOUCH_CS, TOUCH_IRQ); + +void initTouch() +{ + SPI.begin(TOUCH_CLK, TOUCH_MISO, TOUCH_MOSI, TOUCH_CS); + touchscreen.begin(); + touchscreen.setRotation(1); +} + +bool getTouchPoint(uint16_t &x, uint16_t &y, uint16_t &z) +{ + if (!(touchscreen.tirqTouched() && touchscreen.touched())) + { + return false; + } + + TS_Point p = touchscreen.getPoint(); + + // CYD working example ranges + x = map(p.x, 200, 3700, 1, SCREEN_WIDTH); + y = map(p.y, 240, 3800, 1, SCREEN_HEIGHT); + z = p.z; + + // lihtne sanity check + if (x > SCREEN_WIDTH || y > SCREEN_HEIGHT || z == 0) + { + return false; + } + + return true; +} \ No newline at end of file diff --git a/CYD/main.cpp b/CYD/main.cpp index ab0fe3d..b8a7b51 100644 --- a/CYD/main.cpp +++ b/CYD/main.cpp @@ -1,6 +1,7 @@ #include #include "AnimationPlayer.h" #include "LED_Solution.h" +#include "TouchHandler.h" void handleCommand(String cmd) { @@ -38,6 +39,7 @@ void setup() { Serial.begin(115200); used_to_be_setup();//Edited setup from animationplayer. + initTouch(); setupLed(); switchFolder("/pride"); @@ -46,6 +48,8 @@ void setup() { } +bool touchWasDown = false; + void loop() { if (Serial.available()){ String cmd = Serial.readStringUntil('\n'); @@ -53,4 +57,19 @@ void loop() { } updateAnimationPlayer(); + + uint16_t x, y, z; + bool touchNow = getTouchPoint(x, y, z); + + if (touchNow && !touchWasDown) + { + Serial.print("X = "); + Serial.print(x); + Serial.print(" | Y = "); + Serial.print(y); + Serial.print(" | Z = "); + Serial.println(z); + } + + touchWasDown = touchNow; } \ No newline at end of file