// demonstrates drawing and touch operations.
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
#define red_pot A0
#define green_pot A1
#define blue_pot A2
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ts = Adafruit_FT6206();
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup(void)
{
Serial.begin(9600);
tft.begin();
if (!ts.begin(40)) {
Serial.println("Unable to start touchscreen.");
}
else {
Serial.println("Touchscreen started.");
}
tft.fillScreen(ILI9341_WHITE);
tft.setTextSize(2);
// origin = left,top landscape (USB left upper)
}
//x 16bit 5bit 6bit 5bit
//color red green blue
uint32_t x = 0;
uint16_t temp = 0;
uint16_t last_x = 1;
void loop()
{
temp = ((uint16_t)analogRead(red_pot))>>5;
x = temp ;
temp = ((uint16_t)analogRead(green_pot))>>4;
x = (x<<6) + temp;
temp = ((uint16_t)analogRead(blue_pot))>>5;
x = (x<<5) + temp;
if(x != last_x) // so not to waist time in these slow functions
{
tft.setCursor( 0,20 );
tft.setTextColor(x);
tft.println("Drawing Color: ");
tft.fillCircle(180, 22, 7, x);
last_x = x;
}
for(temp = 0 ; temp < 1000 ; temp++) // spend more time here than reading analog
{
if (ts.touched())
{
// Retrieve a point
TS_Point p = ts.getPoint();
// rotate coordinate system
// flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
//Serial.println("touched");
tft.fillCircle(p.x, p.y, 5, x);
}
delayMicroseconds(10);
}
}Loading
ili9341-cap-touch
ili9341-cap-touch