Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CYD/LED_Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <Arduino.h>

//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);
}
45 changes: 45 additions & 0 deletions CYD/TouchHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <Arduino.h>
#include <SPI.h>
#include <XPT2046_Touchscreen.h>
#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;
}
27 changes: 26 additions & 1 deletion CYD/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <Arduino.h>
#include "AnimationPlayer.h"
#include "LED_Solution.h"
#include "TouchHandler.h"

void handleCommand(String cmd)
{
Expand All @@ -12,16 +14,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
Expand All @@ -33,18 +38,38 @@ void handleCommand(String cmd)
void setup() {
Serial.begin(115200);

used_to_be_setup();
used_to_be_setup();//Edited setup from animationplayer.
initTouch();
setupLed();
switchFolder("/pride");


Serial.println("Ready for UART commands");

}

bool touchWasDown = false;

void loop() {
if (Serial.available()){
String cmd = Serial.readStringUntil('\n');
handleCommand(cmd);
}

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;
}