├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── Adafruit_FT6206.cpp ├── Adafruit_FT6206.h ├── README.md ├── examples ├── CapTouchPaint │ └── CapTouchPaint.ino └── CapTouch_onoffbutton │ └── CapTouch_onoffbutton.ino └── library.properties /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit FT6206 Arduino Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /Adafruit_FT6206.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_FT6206.cpp 3 | * 4 | * @mainpage Adafruit FT2606 Library 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * This is a library for the Adafruit Capacitive Touch Screens 9 | * 10 | * ----> http://www.adafruit.com/products/1947 11 | * 12 | * Check out the links above for our tutorials and wiring diagrams 13 | * This chipset uses I2C to communicate 14 | * 15 | * Adafruit invests time and resources providing this open source code, 16 | * please support Adafruit and open-source hardware by purchasing 17 | * products from Adafruit! 18 | * 19 | * @section author Author 20 | * 21 | * Written by Limor Fried/Ladyada for Adafruit Industries. 22 | * 23 | * @section license License 24 | 25 | * MIT license, all text above must be included in any redistribution 26 | */ 27 | 28 | #include 29 | 30 | //#define FT6206_DEBUG 31 | 32 | /**************************************************************************/ 33 | /*! 34 | @brief Instantiates a new FT6206 class 35 | */ 36 | /**************************************************************************/ 37 | // I2C, no address adjustments or pins 38 | Adafruit_FT6206::Adafruit_FT6206() { touches = 0; } 39 | 40 | /**************************************************************************/ 41 | /*! 42 | @brief Setups the I2C interface and hardware, identifies if chip is found 43 | @param thresh Optional threshhold-for-touch value, default is 44 | FT6206_DEFAULT_THRESHOLD but you can try changing it if your screen is 45 | too/not sensitive. You can also try 0 to not change the threshold. 46 | @param theWire Which I2C bus to use, defaults to &Wire 47 | @param i2c_addr The I2C address we expect to find the touch panel at 48 | @returns True if an FT captouch is found, false on any failure 49 | */ 50 | /**************************************************************************/ 51 | bool Adafruit_FT6206::begin(uint8_t thresh, TwoWire *theWire, 52 | uint8_t i2c_addr) { 53 | if (i2c_dev) 54 | delete i2c_dev; 55 | i2c_dev = new Adafruit_I2CDevice(i2c_addr, theWire); 56 | if (!i2c_dev->begin()) 57 | return false; 58 | 59 | #ifdef FT6206_DEBUG 60 | Serial.print("Vend ID: 0x"); 61 | Serial.println(readRegister8(FT62XX_REG_VENDID), HEX); 62 | Serial.print("Chip ID: 0x"); 63 | Serial.println(readRegister8(FT62XX_REG_CHIPID), HEX); 64 | Serial.print("Firm V: "); 65 | Serial.println(readRegister8(FT62XX_REG_FIRMVERS)); 66 | Serial.print("Point Rate Hz: "); 67 | Serial.println(readRegister8(FT62XX_REG_POINTRATE)); 68 | Serial.print("Thresh: "); 69 | Serial.println(readRegister8(FT62XX_REG_THRESHHOLD)); 70 | 71 | // dump all registers 72 | for (int16_t i = 0; i < 0x10; i++) { 73 | Serial.print("I2C $"); 74 | Serial.print(i, HEX); 75 | Serial.print(" = 0x"); 76 | Serial.println(readRegister8(i), HEX); 77 | } 78 | #endif 79 | 80 | // change threshhold to be higher/lower if desired 81 | if (thresh != 0) 82 | writeRegister8(FT62XX_REG_THRESHHOLD, thresh); 83 | 84 | if (readRegister8(FT62XX_REG_VENDID) != FT62XX_VENDID) { 85 | return false; 86 | } 87 | uint8_t id = readRegister8(FT62XX_REG_CHIPID); 88 | if ((id != FT6206_CHIPID) && (id != FT6236_CHIPID) && 89 | (id != FT6236U_CHIPID) && (id != FT6336U_CHIPID)) { 90 | return false; 91 | } 92 | 93 | return true; 94 | } 95 | 96 | /**************************************************************************/ 97 | /*! 98 | @brief Determines if there are any touches detected 99 | @returns Number of touches detected, can be 0, 1 or 2 100 | */ 101 | /**************************************************************************/ 102 | uint8_t Adafruit_FT6206::touched(void) { 103 | uint8_t n = readRegister8(FT62XX_REG_NUMTOUCHES); 104 | if (n > 2) { 105 | n = 0; 106 | } 107 | return n; 108 | } 109 | 110 | /**************************************************************************/ 111 | /*! 112 | @brief Queries the chip and retrieves a point data 113 | @param n The # index (0 or 1) to the points we can detect. In theory we can 114 | detect 2 points but we've found that you should only use this for 115 | single-touch since the two points cant share the same half of the screen. 116 | @returns {@link TS_Point} object that has the x and y coordinets set. If the 117 | z coordinate is 0 it means the point is not touched. If z is 1, it is 118 | currently touched. 119 | */ 120 | /**************************************************************************/ 121 | TS_Point Adafruit_FT6206::getPoint(uint8_t n) { 122 | readData(); 123 | if ((touches == 0) || (n > 1)) { 124 | return TS_Point(0, 0, 0); 125 | } else { 126 | return TS_Point(touchX[n], touchY[n], 1); 127 | } 128 | } 129 | 130 | /************ lower level i/o **************/ 131 | 132 | /**************************************************************************/ 133 | /*! 134 | @brief Reads the bulk of data from captouch chip. Fill in {@link touches}, 135 | {@link touchX}, {@link touchY} and {@link touchID} with results 136 | */ 137 | /**************************************************************************/ 138 | void Adafruit_FT6206::readData(void) { 139 | 140 | uint8_t i2cdat[16]; 141 | uint8_t addr = 0; 142 | i2c_dev->write_then_read(&addr, 1, i2cdat, 16); 143 | 144 | touches = i2cdat[0x02]; 145 | #ifdef FT6206_DEBUG 146 | Serial.print("# Touches: "); 147 | Serial.println(touches); 148 | #endif 149 | if ((touches > 2) || (touches == 0)) { 150 | touches = 0; 151 | } 152 | 153 | #ifdef FT6206_DEBUG 154 | for (uint8_t i = 0; i < 16; i++) { 155 | Serial.print("0x"); 156 | Serial.print(i2cdat[i], HEX); 157 | Serial.print(" "); 158 | } 159 | Serial.println(); 160 | if (i2cdat[0x01] != 0x00) { 161 | Serial.print("Gesture #"); 162 | Serial.println(i2cdat[0x01]); 163 | } 164 | #endif 165 | 166 | for (uint8_t i = 0; i < 2; i++) { 167 | touchX[i] = i2cdat[0x03 + i * 6] & 0x0F; 168 | touchX[i] <<= 8; 169 | touchX[i] |= i2cdat[0x04 + i * 6]; 170 | touchY[i] = i2cdat[0x05 + i * 6] & 0x0F; 171 | touchY[i] <<= 8; 172 | touchY[i] |= i2cdat[0x06 + i * 6]; 173 | touchID[i] = i2cdat[0x05 + i * 6] >> 4; 174 | } 175 | 176 | #ifdef FT6206_DEBUG 177 | Serial.println(); 178 | for (uint8_t i = 0; i < touches; i++) { 179 | Serial.print("ID #"); 180 | Serial.print(touchID[i]); 181 | Serial.print("\t("); 182 | Serial.print(touchX[i]); 183 | Serial.print(", "); 184 | Serial.print(touchY[i]); 185 | Serial.print(") "); 186 | } 187 | Serial.println(); 188 | #endif 189 | } 190 | 191 | uint8_t Adafruit_FT6206::readRegister8(uint8_t reg) { 192 | uint8_t buffer[1] = {reg}; 193 | i2c_dev->write_then_read(buffer, 1, buffer, 1); 194 | return buffer[0]; 195 | } 196 | 197 | void Adafruit_FT6206::writeRegister8(uint8_t reg, uint8_t val) { 198 | uint8_t buffer[2] = {reg, val}; 199 | i2c_dev->write(buffer, 2); 200 | } 201 | 202 | /* 203 | 204 | // DONT DO THIS - REALLY - IT DOESNT WORK 205 | void Adafruit_FT6206::autoCalibrate(void) { 206 | writeRegister8(FT06_REG_MODE, FT6206_REG_FACTORYMODE); 207 | delay(100); 208 | //Serial.println("Calibrating..."); 209 | writeRegister8(FT6206_REG_CALIBRATE, 4); 210 | delay(300); 211 | for (uint8_t i = 0; i < 100; i++) { 212 | uint8_t temp; 213 | temp = readRegister8(FT6206_REG_MODE); 214 | Serial.println(temp, HEX); 215 | //return to normal mode, calibration finish 216 | if (0x0 == ((temp & 0x70) >> 4)) 217 | break; 218 | } 219 | delay(200); 220 | //Serial.println("Calibrated"); 221 | delay(300); 222 | writeRegister8(FT6206_REG_MODE, FT6206_REG_FACTORYMODE); 223 | delay(100); 224 | writeRegister8(FT6206_REG_CALIBRATE, 5); 225 | delay(300); 226 | writeRegister8(FT6206_REG_MODE, FT6206_REG_WORKMODE); 227 | delay(300); 228 | } 229 | */ 230 | 231 | /****************/ 232 | 233 | /**************************************************************************/ 234 | /*! 235 | @brief Instantiates a new FT6206 class with x, y and z set to 0 by default 236 | */ 237 | /**************************************************************************/ 238 | TS_Point::TS_Point(void) { x = y = z = 0; } 239 | 240 | /**************************************************************************/ 241 | /*! 242 | @brief Instantiates a new FT6206 class with x, y and z set by params. 243 | @param _x The X coordinate 244 | @param _y The Y coordinate 245 | @param _z The Z coordinate 246 | */ 247 | /**************************************************************************/ 248 | 249 | TS_Point::TS_Point(int16_t _x, int16_t _y, int16_t _z) { 250 | x = _x; 251 | y = _y; 252 | z = _z; 253 | } 254 | 255 | /**************************************************************************/ 256 | /*! 257 | @brief Simple == comparator for two TS_Point objects 258 | @returns True if x, y and z are the same for both points, False otherwise. 259 | */ 260 | /**************************************************************************/ 261 | bool TS_Point::operator==(TS_Point p1) { 262 | return ((p1.x == x) && (p1.y == y) && (p1.z == z)); 263 | } 264 | 265 | /**************************************************************************/ 266 | /*! 267 | @brief Simple != comparator for two TS_Point objects 268 | @returns False if x, y and z are the same for both points, True otherwise. 269 | */ 270 | /**************************************************************************/ 271 | bool TS_Point::operator!=(TS_Point p1) { 272 | return ((p1.x != x) || (p1.y != y) || (p1.z != z)); 273 | } 274 | -------------------------------------------------------------------------------- /Adafruit_FT6206.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_FT6206.h 3 | */ 4 | 5 | #ifndef ADAFRUIT_FT6206_LIBRARY 6 | #define ADAFRUIT_FT6206_LIBRARY 7 | 8 | #include "Arduino.h" 9 | #include 10 | 11 | #define FT62XX_DEFAULT_ADDR 0x38 //!< I2C address 12 | #define FT62XX_G_FT5201ID 0xA8 //!< FocalTech's panel ID 13 | #define FT62XX_REG_NUMTOUCHES 0x02 //!< Number of touch points 14 | 15 | #define FT62XX_NUM_X 0x33 //!< Touch X position 16 | #define FT62XX_NUM_Y 0x34 //!< Touch Y position 17 | 18 | #define FT62XX_REG_MODE 0x00 //!< Device mode, either WORKING or FACTORY 19 | #define FT62XX_REG_CALIBRATE 0x02 //!< Calibrate mode 20 | #define FT62XX_REG_WORKMODE 0x00 //!< Work mode 21 | #define FT62XX_REG_FACTORYMODE 0x40 //!< Factory mode 22 | #define FT62XX_REG_THRESHHOLD 0x80 //!< Threshold for touch detection 23 | #define FT62XX_REG_POINTRATE 0x88 //!< Point rate 24 | #define FT62XX_REG_FIRMVERS 0xA6 //!< Firmware version 25 | #define FT62XX_REG_CHIPID 0xA3 //!< Chip selecting 26 | #define FT62XX_REG_VENDID 0xA8 //!< FocalTech's panel ID 27 | 28 | #define FT62XX_VENDID 0x11 //!< FocalTech's panel ID 29 | #define FT6206_CHIPID 0x06 //!< Chip selecting 30 | #define FT6236_CHIPID 0x36 //!< Chip selecting 31 | #define FT6236U_CHIPID 0x64 //!< Chip selecting 32 | #define FT6336U_CHIPID 0x64 //!< Chip selecting 33 | 34 | // calibrated for Adafruit 2.8" ctp screen 35 | #define FT62XX_DEFAULT_THRESHOLD 128 //!< Default threshold for touch detection 36 | 37 | /**************************************************************************/ 38 | /*! 39 | @brief Helper class that stores a TouchScreen Point with x, y, and z 40 | coordinates, for easy math/comparison 41 | */ 42 | /**************************************************************************/ 43 | class TS_Point { 44 | public: 45 | TS_Point(void); 46 | TS_Point(int16_t x, int16_t y, int16_t z); 47 | 48 | bool operator==(TS_Point); 49 | bool operator!=(TS_Point); 50 | 51 | int16_t x; /*!< X coordinate */ 52 | int16_t y; /*!< Y coordinate */ 53 | int16_t z; /*!< Z coordinate (often used for pressure) */ 54 | }; 55 | 56 | /**************************************************************************/ 57 | /*! 58 | @brief Class that stores state and functions for interacting with FT6206 59 | capacitive touch chips 60 | */ 61 | /**************************************************************************/ 62 | class Adafruit_FT6206 { 63 | public: 64 | Adafruit_FT6206(void); 65 | bool begin(uint8_t thresh = FT62XX_DEFAULT_THRESHOLD, 66 | TwoWire *theWire = &Wire, uint8_t i2c_addr = FT62XX_DEFAULT_ADDR); 67 | uint8_t touched(void); 68 | TS_Point getPoint(uint8_t n = 0); 69 | 70 | // void autoCalibrate(void); 71 | 72 | private: 73 | Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface 74 | void writeRegister8(uint8_t reg, uint8_t val); 75 | uint8_t readRegister8(uint8_t reg); 76 | 77 | void readData(void); 78 | uint8_t touches; 79 | uint16_t touchX[2], touchY[2], touchID[2]; 80 | }; 81 | 82 | #endif // ADAFRUIT_FT6206_LIBRARY 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit_FT6206 Library [![Build Status](https://github.com/adafruit/Adafruit_FT6206_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_FT6206_Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_FT6206_Library/html/index.html) 2 | 3 | 4 | 5 | This is a library for the Adafruit FT6206-Based capacitive touch screens and displays: 6 | * https://www.adafruit.com/products/1947 7 | * https://www.adafruit.com/product/1651 8 | 9 | Also supports FT6236 chips (and maybe other compatible chips!) 10 | 11 | Check out the links above for our tutorials and wiring diagrams. This chip uses I2C to communicate 12 | 13 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 14 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. 16 | MIT license, all text above must be included in any redistribution 17 | 18 | -------------------------------------------------------------------------------- /examples/CapTouchPaint/CapTouchPaint.ino: -------------------------------------------------------------------------------- 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 // Core graphics library 18 | #include // this is needed for display 19 | #include 20 | #include // this is needed for FT6206 21 | #include 22 | 23 | // The FT6206 uses hardware I2C (SCL/SDA) 24 | Adafruit_FT6206 ctp = Adafruit_FT6206(); 25 | 26 | // The display also uses hardware SPI, plus #9 & #10 27 | #define TFT_CS 10 28 | #define TFT_DC 9 29 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 30 | 31 | // Size of the color selection boxes and the paintbrush size 32 | #define BOXSIZE 40 33 | #define PENRADIUS 3 34 | int oldcolor, currentcolor; 35 | 36 | void setup(void) { 37 | Serial.begin(115200); 38 | while (!Serial) delay(10); // pause the serial port 39 | 40 | Serial.println(F("Cap Touch Paint!")); 41 | 42 | tft.begin(); 43 | 44 | if (! ctp.begin(40, &Wire)) { // pass in 'sensitivity' coefficient and I2C bus 45 | Serial.println("Couldn't start FT6206 touchscreen controller"); 46 | while (1) delay(10); 47 | } 48 | 49 | Serial.println("Capacitive touchscreen started"); 50 | 51 | tft.fillScreen(ILI9341_BLACK); 52 | 53 | // make the color selection boxes 54 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 55 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 56 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 57 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 58 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 59 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 60 | 61 | // select the current color 'red' 62 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 63 | currentcolor = ILI9341_RED; 64 | } 65 | 66 | void loop() { 67 | // Wait for a touch 68 | if (! ctp.touched()) { 69 | return; 70 | } 71 | 72 | // Retrieve a point 73 | TS_Point p = ctp.getPoint(); 74 | 75 | /* 76 | // Print out raw data from screen touch controller 77 | Serial.print("X = "); Serial.print(p.x); 78 | Serial.print("\tY = "); Serial.print(p.y); 79 | Serial.print(" -> "); 80 | */ 81 | 82 | // flip it around to match the screen. 83 | p.x = map(p.x, 0, 240, 240, 0); 84 | p.y = map(p.y, 0, 320, 320, 0); 85 | 86 | // Print out the remapped (rotated) coordinates 87 | Serial.print("("); Serial.print(p.x); 88 | Serial.print(", "); Serial.print(p.y); 89 | Serial.println(")"); 90 | 91 | 92 | if (p.y < BOXSIZE) { 93 | oldcolor = currentcolor; 94 | 95 | if (p.x < BOXSIZE) { 96 | currentcolor = ILI9341_RED; 97 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 98 | } else if (p.x < BOXSIZE*2) { 99 | currentcolor = ILI9341_YELLOW; 100 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 101 | } else if (p.x < BOXSIZE*3) { 102 | currentcolor = ILI9341_GREEN; 103 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 104 | } else if (p.x < BOXSIZE*4) { 105 | currentcolor = ILI9341_CYAN; 106 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 107 | } else if (p.x < BOXSIZE*5) { 108 | currentcolor = ILI9341_BLUE; 109 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 110 | } else if (p.x <= BOXSIZE*6) { 111 | currentcolor = ILI9341_MAGENTA; 112 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE); 113 | } 114 | 115 | if (oldcolor != currentcolor) { 116 | if (oldcolor == ILI9341_RED) 117 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED); 118 | if (oldcolor == ILI9341_YELLOW) 119 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW); 120 | if (oldcolor == ILI9341_GREEN) 121 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN); 122 | if (oldcolor == ILI9341_CYAN) 123 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN); 124 | if (oldcolor == ILI9341_BLUE) 125 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE); 126 | if (oldcolor == ILI9341_MAGENTA) 127 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA); 128 | } 129 | } 130 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 131 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 132 | } 133 | } -------------------------------------------------------------------------------- /examples/CapTouch_onoffbutton/CapTouch_onoffbutton.ino: -------------------------------------------------------------------------------- 1 | //This example implements a simple sliding On/Off button. The example 2 | // demonstrates drawing and touch operations. 3 | // 4 | //Thanks to Adafruit forums member Asteroid for the original sketch! 5 | // 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | // The FT6206 uses hardware I2C (SCL/SDA) 13 | Adafruit_FT6206 ts = Adafruit_FT6206(); 14 | 15 | #define TFT_CS 10 16 | #define TFT_DC 9 17 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 18 | 19 | boolean RecordOn = false; 20 | 21 | #define FRAME_X 210 22 | #define FRAME_Y 180 23 | #define FRAME_W 100 24 | #define FRAME_H 50 25 | 26 | #define REDBUTTON_X FRAME_X 27 | #define REDBUTTON_Y FRAME_Y 28 | #define REDBUTTON_W (FRAME_W/2) 29 | #define REDBUTTON_H FRAME_H 30 | 31 | #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) 32 | #define GREENBUTTON_Y FRAME_Y 33 | #define GREENBUTTON_W (FRAME_W/2) 34 | #define GREENBUTTON_H FRAME_H 35 | 36 | void drawFrame() 37 | { 38 | tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK); 39 | } 40 | 41 | void redBtn() 42 | { 43 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED); 44 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE); 45 | drawFrame(); 46 | tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2)); 47 | tft.setTextColor(ILI9341_WHITE); 48 | tft.setTextSize(2); 49 | tft.println("ON"); 50 | RecordOn = false; 51 | } 52 | 53 | void greenBtn() 54 | { 55 | tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN); 56 | tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE); 57 | drawFrame(); 58 | tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2)); 59 | tft.setTextColor(ILI9341_WHITE); 60 | tft.setTextSize(2); 61 | tft.println("OFF"); 62 | RecordOn = true; 63 | } 64 | 65 | void setup(void) 66 | { 67 | Serial.begin(9600); 68 | tft.begin(); 69 | if (!ts.begin(40)) { 70 | Serial.println("Unable to start touchscreen."); 71 | } 72 | else { 73 | Serial.println("Touchscreen started."); 74 | } 75 | 76 | tft.fillScreen(ILI9341_BLACK); 77 | // origin = left,top landscape (USB left upper) 78 | tft.setRotation(1); 79 | redBtn(); 80 | } 81 | 82 | void loop() 83 | { 84 | // See if there's any touch data for us 85 | if (ts.touched()) 86 | { 87 | // Retrieve a point 88 | TS_Point p = ts.getPoint(); 89 | // rotate coordinate system 90 | // flip it around to match the screen. 91 | p.x = map(p.x, 0, 240, 240, 0); 92 | p.y = map(p.y, 0, 320, 320, 0); 93 | int y = tft.height() - p.x; 94 | int x = p.y; 95 | 96 | if (RecordOn) 97 | { 98 | if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) { 99 | if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) { 100 | Serial.println("Red btn hit"); 101 | redBtn(); 102 | } 103 | } 104 | } 105 | else //Record is off (RecordOn == false) 106 | { 107 | if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) { 108 | if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) { 109 | Serial.println("Green btn hit"); 110 | greenBtn(); 111 | } 112 | } 113 | } 114 | 115 | Serial.println(RecordOn); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit FT6206 Library 2 | version=1.1.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for FT6206-based Capacitive touch screen 6 | paragraph=Arduino library for FT6206-based Capacitive touch screen 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_FT6206_Library 9 | architectures=* 10 | depends=Adafruit ILI9341, Adafruit GFX Library 11 | --------------------------------------------------------------------------------