/*
This code was created by user Liam Frahmann.
This is an example of how to use the Adafruit ILI9341 Capacitive Touch.
Connections:
SCL to A5
SDA to A4
MISO to 12
LED to 3.3V or PWM for brightness(Not supported in WokWi)
SCK to 13
MOSI to 11
D/C to 9
RST to 8
CS to 10
GND to GND of power supply
VCC to 5V
*/
#include <Adafruit_GFX.h>
#include <Adafruit_FT6206.h>
#include <Adafruit_ILI9341.h>
//Defining the pins that arn't Hardware SPI.
static byte SPI_PIN_CS = 10;
static byte PIN_DC = 9;
static byte PIN_RST = 8;
//Defining spaces for the colors so as to use a value than can be changed
static byte X_SPACE = 40;
static byte Y_SPACE = 40;
//Creating two values for adjusting the color display to look nice
uint32_t pixelColor;
int scale = 1, saver = scale;
//Creating an object called "tft" that can be called by any of the functions in the Adafruit_GFX and
//Adafruit ILI9341 Libraries. Because the ILI9341 Cap Touch uses SPI, the hardware pins can be used
//for better and more reliable preformance
Adafruit_ILI9341 tft = Adafruit_ILI9341(SPI_PIN_CS, PIN_DC, PIN_SPI_MOSI, PIN_SPI_SCK, PIN_RST, PIN_SPI_MISO);
//Creating an object called "ts". Because the Capacitive Touch is I2C, nothing is defined here, but
//SDA and SCL must be properly connected or it will not work at all.
Adafruit_FT6206 ts = Adafruit_FT6206();
void setup() {
Serial.begin(9600);
tft.begin(); //Initalizes the object called "tft" under the Adafruit ILI9341 Library
tft.setRotation(2); //Conforms the tft to be at the same rotation as the Capacitive Touch
ts.begin(); //Initalizes the object ccalled "ts" under the Adafruit FT6206 Libary in I2C
pixelColor = ILI9341_RED;
//Creating the top portion of color selection
tft.fillRect(0,0,40,40,ILI9341_RED);
tft.fillRect(40,0,40,40,ILI9341_GREEN);
tft.fillRect(80,0,40,40,ILI9341_BLUE);
tft.fillRect(120,0,40,40,ILI9341_YELLOW);
tft.fillRect(160,0,40,40,ILI9341_MAGENTA);
tft.fillRect(200,0,40,40,ILI9341_CYAN);
Serial.println("Enter a scale to get bigger dots!");
}
void loop() {
if(Serial.available()){
scale = Serial.parseInt();
if(scale == 0)scale = saver;else saver = scale;
Serial.print(scale);
Serial.println("");
Serial.flush();
scale = 100 - scale + 1;
}
TS_Point p; // Creates an object called "p" that contains the data for the points touched on the TFT
if(ts.touched()){
p = ts.getPoint();
if(p.y > Y_SPACE)tft.fillCircle(p.x,p.y,scale,pixelColor);
/*Here, this loop is to check the values for each of the colors if they've been touched */
for(byte x = 0; x < 6; x++){
//Checking to see if the ts reports a touch within the x and y corodinites of the other colors
//acording to the byte x.
if(p.x >= x * X_SPACE && p.x <= (x + 1) * X_SPACE && p.y <= Y_SPACE){
switch(x){
case 0: pixelColor = ILI9341_RED; break;
case 1: pixelColor = ILI9341_GREEN; break;
case 2: pixelColor = ILI9341_BLUE; break;
case 3: pixelColor = ILI9341_YELLOW; break;
case 4: pixelColor = ILI9341_MAGENTA; break;
case 5: pixelColor = ILI9341_CYAN; break;
}
}
}
}
}