Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
CapTouchPaint.ino
Go to the documentation of this file.
1 /***************************************************
2  This is our touchscreen painting example for the Adafruit ILI9341
3  captouch shield
4  ----> http://www.adafruit.com/products/1947
5 
6  Check out the links above for our tutorials and wiring diagrams
7 
8  Adafruit invests time and resources providing this open source code,
9  please support Adafruit and open-source hardware by purchasing
10  products from Adafruit!
11 
12  Written by Limor Fried/Ladyada for Adafruit Industries.
13  MIT license, all text above must be included in any redistribution
14  ****************************************************/
15 
16 
17 #include <Adafruit_GFX.h> // Core graphics library
18 #include <SPI.h> // this is needed for display
19 #include <Adafruit_ILI9341.h>
20 #include <Wire.h> // this is needed for FT6206
21 #include <Adafruit_FT6206.h>
22 
23 // The FT6206 uses hardware I2C (SCL/SDA)
25 
26 // The display also uses hardware SPI, plus #9 & #10
27 #define TFT_CS 10
28 #define TFT_DC 9
30 
31 // Size of the color selection boxes and the paintbrush size
32 #define BOXSIZE 40
33 #define PENRADIUS 3
35 
36 void setup(void)
37 {
38  while (!Serial); // used for leonardo debugging
39 
40  Serial.begin(115200);
41  Serial.println(F("Cap Touch Paint!"));
42 
43  tft.begin();
44 
45  if (! ctp.begin(40)) // pass in 'sensitivity' coefficient
46  {
47  Serial.println("Couldn't start FT6206 touchscreen controller");
48  while (1);
49  }
50 
51  Serial.println("Capacitive touchscreen started");
52 
54 
55  // make the color selection boxes
56  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
62 
63  // select the current color 'red'
66 }
67 
68 void loop()
69 {
70  // Wait for a touch
71  if (! ctp.touched())
72  {
73  return;
74  }
75 
76  // Retrieve a point
77  TS_Point p = ctp.getPoint();
78 
79  /*
80  // Print out raw data from screen touch controller
81  Serial.print("X = "); Serial.print(p.x);
82  Serial.print("\tY = "); Serial.print(p.y);
83  Serial.print(" -> ");
84  */
85 
86  // flip it around to match the screen.
87  p.x = map(p.x, 0, 240, 240, 0);
88  p.y = map(p.y, 0, 320, 320, 0);
89 
90  // Print out the remapped (rotated) coordinates
91  Serial.print("(");
92  Serial.print(p.x);
93  Serial.print(", ");
94  Serial.print(p.y);
95  Serial.println(")");
96 
97 
98  if (p.y < BOXSIZE)
99  {
101 
102  if (p.x < BOXSIZE)
103  {
105  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
106  }
107  else if (p.x < BOXSIZE*2)
108  {
111  }
112  else if (p.x < BOXSIZE*3)
113  {
116  }
117  else if (p.x < BOXSIZE*4)
118  {
121  }
122  else if (p.x < BOXSIZE*5)
123  {
126  }
127  else if (p.x <= BOXSIZE*6)
128  {
131  }
132 
133  if (oldcolor != currentcolor)
134  {
135  if (oldcolor == ILI9341_RED)
136  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
137  if (oldcolor == ILI9341_YELLOW)
139  if (oldcolor == ILI9341_GREEN)
141  if (oldcolor == ILI9341_CYAN)
143  if (oldcolor == ILI9341_BLUE)
145  if (oldcolor == ILI9341_MAGENTA)
147  }
148  }
149  if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height()))
150  {
151  tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
152  }
153 }
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
#define PENRADIUS
int16_t x
Adafruit_ILI9341 tft
static void loop()
int16_t height(void) const
#define BOXSIZE
#define ILI9341_WHITE
#define ILI9341_MAGENTA
Adafruit_FT6206 ctp
#define TFT_CS
#define ILI9341_BLACK
#define ILI9341_RED
int16_t y
#define ILI9341_YELLOW
#define TFT_DC
boolean begin(uint8_t thresh=FT6206_DEFAULT_THRESSHOLD)
Setups the HW.
#define ILI9341_BLUE
#define ILI9341_CYAN
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
#define ILI9341_GREEN
void fillScreen(uint16_t color)
TS_Point getPoint(void)
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
static int oldcolor
static int currentcolor
boolean touched(void)
static void setup(void)