Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SuGlider authored Nov 30, 2022
1 parent 402413d commit 7fa49ff
Show file tree
Hide file tree
Showing 11 changed files with 1,115 additions and 21 deletions.
39 changes: 18 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
MIT License

Copyright (c) 2022 Rodrigo Garcia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Copyright 2022 Rodrigo Garcia <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
118 changes: 118 additions & 0 deletions examples/CapTouchPaint/CapTouchPaint.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
This sketch targets the ESP32-S3-BOX board ONLY
It demonstrates a compatible Touch Screen sketch
*/

// Testing if the user has selected the right board in the menu
#ifndef TT21100_ADDR
#error Please select the right board in the Arduino IDE: ESP32-S3-Box
#endif

#include "ESP32_S3_Box_TFT.h"
#include "ESP32_S3_Box_TouchScreen.h"

ESP32S3BOX_TFT tft = ESP32S3BOX_TFT();
ESP32S3BOX_TS ts = ESP32S3BOX_TS();

// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup(void) {
Serial.begin(115200);
delay(500);

Serial.println("Cap Touch Paint!");

tft.init();

if (! ts.begin()) {
Serial.println("Couldn't start TT21100 touchscreen controller");
while (1);
}

Serial.println("Capacitive touchscreen started");

tft.fillScreen(ST7789_BLACK);

// make the color selection boxes
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ST7789_RED);
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ST7789_YELLOW);
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ST7789_GREEN);
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ST7789_CYAN);
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ST7789_BLUE);
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ST7789_MAGENTA);

// select the current color 'red'
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
currentcolor = ST7789_RED;
}

void loop() {
// Wait for a touch
if (! ts.touched()) {
return;
}

// Retrieve a point
TS_Point p = ts.getPoint();


// Print out raw data from screen touch controller
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print(" -> ");


// flip X around to match the screen.
p.x = map(p.x, 0, 320, 320, 0);

// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");


if (p.y < BOXSIZE) {
oldcolor = currentcolor;

if (p.x < BOXSIZE) {
currentcolor = ST7789_RED;
tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
} else if (p.x < BOXSIZE*2) {
currentcolor = ST7789_YELLOW;
tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
} else if (p.x < BOXSIZE*3) {
currentcolor = ST7789_GREEN;
tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
} else if (p.x < BOXSIZE*4) {
currentcolor = ST7789_CYAN;
tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
} else if (p.x < BOXSIZE*5) {
currentcolor = ST7789_BLUE;
tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
} else if (p.x <= BOXSIZE*6) {
currentcolor = ST7789_MAGENTA;
tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ST7789_WHITE);
}

if (oldcolor != currentcolor) {
if (oldcolor == ST7789_RED)
tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ST7789_RED);
if (oldcolor == ST7789_YELLOW)
tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ST7789_YELLOW);
if (oldcolor == ST7789_GREEN)
tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ST7789_GREEN);
if (oldcolor == ST7789_CYAN)
tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ST7789_CYAN);
if (oldcolor == ST7789_BLUE)
tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ST7789_BLUE);
if (oldcolor == ST7789_MAGENTA)
tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ST7789_MAGENTA);
}
}
if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
}
}
116 changes: 116 additions & 0 deletions examples/CapTouch_onoffbutton/CapTouch_onoffbutton.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.

// Testing if the user has selected the right board in the menu
#ifndef TT21100_ADDR
#error Please select the right board in the Arduino IDE: ESP32-S3-Box
#endif

#include "ESP32_S3_Box_TFT.h"
#include "ESP32_S3_Box_TouchScreen.h"

ESP32S3BOX_TFT tft = ESP32S3BOX_TFT();
ESP32S3BOX_TS ts = ESP32S3BOX_TS();

boolean RecordOn = false;

#define FRAME_X 110
#define FRAME_Y 130
#define FRAME_W 200
#define FRAME_H 100

#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H

#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H

void drawFrame()
{
tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ST7789_BLACK);
}

void redBtn()
{
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ST7789_RED);
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ST7789_BLUE);
drawFrame();
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
tft.setTextColor(ST7789_BLACK);
tft.setTextSize(3);
tft.println("ON");
tft.setCursor(GREENBUTTON_X + 6 + 3 , GREENBUTTON_Y + (GREENBUTTON_H/2) + 2);
tft.setTextColor(ST7789_CYAN);
tft.setTextSize(3);
tft.println("ON");
RecordOn = false;
}

void greenBtn()
{
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ST7789_GREEN);
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ST7789_BLUE);
drawFrame();
tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
tft.setTextColor(ST7789_BLACK);
tft.setTextSize(3);
tft.println("OFF");
tft.setCursor(REDBUTTON_X + 6 + 3 , REDBUTTON_Y + (REDBUTTON_H/2) + 2);
tft.setTextColor(ST7789_CYAN);
tft.setTextSize(3);
tft.println("OFF");
RecordOn = true;
}

void setup(void)
{
Serial.begin(115200);
tft.init();
if (!ts.begin()) {
Serial.println("Unable to start touchscreen.");
}
else {
Serial.println("Touchscreen started.");
}

tft.fillScreen(ST7789_BLACK);
tft.setRotation(0);
redBtn();
}

void loop()
{
// See if there's any touch data for us
if (ts.touched())
{
// Retrieve a point
TS_Point p = ts.getPoint();
// flip X around to match the screen.
p.x = map(p.x, 0, 320, 320, 0);

if (RecordOn)
{
if((p.x > REDBUTTON_X) && (p.x < (REDBUTTON_X + REDBUTTON_W))) {
if ((p.y > REDBUTTON_Y) && (p.y <= (REDBUTTON_Y + REDBUTTON_H))) {
Serial.println("Red btn hit");
redBtn();
}
}
}
else //Record is off (RecordOn == false)
{
if((p.x > GREENBUTTON_X) && (p.x < (GREENBUTTON_X + GREENBUTTON_W))) {
if ((p.y > GREENBUTTON_Y) && (p.y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
Serial.println("Green btn hit");
greenBtn();
}
}
}

Serial.println(RecordOn);
}
}
Loading

0 comments on commit 7fa49ff

Please sign in to comment.