├── .gitattributes ├── .gitignore ├── PDFs ├── TTP229 Datasheet.pdf ├── TTP229 Modes.pdf └── TTP229 Module.pdf ├── README.md ├── TTP229 Example Code.JPG ├── TTP229 Modes.jpg ├── TTP229 Module.jpg └── TTP229 ├── ReadMe.txt ├── TTP229.cpp ├── TTP229.h ├── examples ├── Calculator │ └── Calculator.ino └── KeyToSerial │ └── KeyToSerial.ino └── keywords.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /PDFs/TTP229 Datasheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/PDFs/TTP229 Datasheet.pdf -------------------------------------------------------------------------------- /PDFs/TTP229 Modes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/PDFs/TTP229 Modes.pdf -------------------------------------------------------------------------------- /PDFs/TTP229 Module.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/PDFs/TTP229 Module.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ttp229-arduino 2 | This is my Ardoaino ttp229 library! 3 | 4 | Copy the "TTP229" library folder to your /libraries/ folder. 5 | Restart the IDE (close and open again). 6 | 7 | Then in Arduino IDE: 8 | File -> Examples -> TTP229 -> KeyToSerial. 9 | File -> Examples -> TTP229 -> Calculator. 10 | 11 | Follow the connection instructions at the beginning of each sample! 12 | In addition I've included a picture that illustrates the connections. 13 | 14 | 15 | Enjoy :) 16 | -------------------------------------------------------------------------------- /TTP229 Example Code.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/TTP229 Example Code.JPG -------------------------------------------------------------------------------- /TTP229 Modes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/TTP229 Modes.jpg -------------------------------------------------------------------------------- /TTP229 Module.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino12/ttp229b-arduino/e11d5c0bf9eb38ddf3858b07fd3915553874b6ac/TTP229 Module.jpg -------------------------------------------------------------------------------- /TTP229/ReadMe.txt: -------------------------------------------------------------------------------- 1 | /*********************************** LICENCE ***********************************\ 2 | | Copyright (c) 2014, A.E. TEC | 3 | | All rights reserved. | 4 | | | 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the following conditions are met: | 7 | | | 8 | | * Redistributions of source code must retain the above copyright notice, | 9 | | this list of conditions and the following disclaimer. | 10 | | * Redistributions in binary form must reproduce the above copyright notice, | 11 | | this list of conditions and the following disclaimer in the documentation | 12 | | and/or other materials provided with the distribution. | 13 | | | 14 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 18 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 | | POSSIBILITY OF SUCH DAMAGE. | 25 | \*****************************************************************************/ 26 | /************************************ USES ************************************\ 27 | | This library designed to communicate with the TTP229 chip from an Arduino | 28 | | | 29 | | It works with a TTP229 (16-Channel Digital Touch Capacitive Switch Sensor) | 30 | | using the 2-wires serial interface protocol - only 2 arduino pins. | 31 | \*****************************************************************************/ 32 | /*********************************** CIRCUIT ***********************************\ 33 | | General: | 34 | | * TTP229 VCC to pin VCC | 35 | | * TTP229 GND to pin GND | 36 | | * TTP229 SCL to any pin you choose... | 37 | | * TTP229 SDO to any pin you choose... | 38 | | | 39 | | 16 Buttons Mode (else 8 Buttons Mode): | 40 | | * TTP229 TP2 to GND via 1 Megohm resistor! | 41 | | # Must use the ReadKey16, GetKeys16... else use the ReadKey8, GetKeys8... | 42 | | | 43 | | Multi Keys Mode (else Single key Mode): | 44 | | * TTP229 TP3 to GND via 1 Megohm resistor! | 45 | | * TTP229 TP4 to GND via 1 Megohm resistor! | 46 | | | 47 | | 64Hz Sampling Rate (else 8Hz Sampling Rate): | 48 | | * TTP229 TP5 to GND via 1 Megohm resistor! | 49 | | | 50 | | 2ms Wake Up Rate (else 4ms Wake Up Rate): | 51 | | * TTP229 TP6 to GND via 1 Megohm resistor! | 52 | | | 53 | | 60sec Key On Timeout (else No Key On Timeout): | 54 | | * TTP229 TP7 to GND via 1 Megohm resistor! | 55 | | | 56 | | Important: | 57 | | * Must reconnect the TTP229 power so the mode changes will take effect | 58 | | * The 1 Megohm resistors already exist on some TTP229 modules | 59 | \*****************************************************************************/ 60 | 61 | Functions: 62 | TTP229(uint8_t sclPin, uint8_t sdoPin); // Constructor 63 | uint8_t 64 | ReadKey8(), // Wait for a key to be touched, then return its index(1 - 8) (When released return 0). 65 | GetKey8(), // If a key is touched, return its index(1 - 8) (else return 0). 66 | ReadKeys8(), // Wait for a touch, then return the keys buffer (each bit represents a key). 67 | GetKeys8(), // Return the keys buffer (each bit represents a key). 68 | ReadKey16(), // Wait for a key to be touched, then return its index(1 - 16) (When released return 0). 69 | GetKey16(); // If a key is touched, return its index(1 - 16) (else return 0). 70 | uint16_t 71 | ReadKeys16(), // Wait for a touch, then return the keys buffer (each bit represents a key). 72 | GetKeys16(); // Return the keys buffer (each bit represents a key). 73 | -------------------------------------------------------------------------------- /TTP229/TTP229.cpp: -------------------------------------------------------------------------------- 1 | /*********************************** LICENCE **********************************\ 2 | | Copyright (c) 2014, A.E. TEC | 3 | | All rights reserved. | 4 | | | 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the following conditions are met: | 7 | | | 8 | | * Redistributions of source code must retain the above copyright notice, | 9 | | this list of conditions and the following disclaimer. | 10 | | * Redistributions in binary form must reproduce the above copyright notice, | 11 | | this list of conditions and the following disclaimer in the documentation | 12 | | and/or other materials provided with the distribution. | 13 | | | 14 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 18 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 | | POSSIBILITY OF SUCH DAMAGE. | 25 | \******************************************************************************/ 26 | /************************************ USES ************************************\ 27 | | This library designed to communicate with the TTP229 chip from an Arduino | 28 | | | 29 | | It works with a TTP229 (16-Channel Digital Touch Capacitive Switch Sensor) | 30 | | using the 2-wires serial interface protocol - only 2 arduino pins. | 31 | \******************************************************************************/ 32 | /*********************************** CIRCUIT **********************************\ 33 | | General: | 34 | | * TTP229 VCC to pin VCC | 35 | | * TTP229 GND to pin GND | 36 | | * TTP229 SCL to any pin you choose... | 37 | | * TTP229 SDO to any pin you choose... | 38 | | | 39 | | 16 Buttons Mode (else 8 Buttons Mode): | 40 | | * TTP229 TP2 to GND via 1 Megohm resistor! | 41 | | # Must use the ReadKey16, GetKeys16... else use the ReadKey8, GetKeys8... | 42 | | | 43 | | Multi Keys Mode (else Single key Mode): | 44 | | * TTP229 TP3 to GND via 1 Megohm resistor! | 45 | | * TTP229 TP4 to GND via 1 Megohm resistor! | 46 | | | 47 | | 64Hz Sampling Rate (else 8Hz Sampling Rate): | 48 | | * TTP229 TP5 to GND via 1 Megohm resistor! | 49 | | | 50 | | 2ms Wake Up Rate (else 4ms Wake Up Rate): | 51 | | * TTP229 TP6 to GND via 1 Megohm resistor! | 52 | | | 53 | | 60sec Key On Timeout (else No Key On Timeout): | 54 | | * TTP229 TP7 to GND via 1 Megohm resistor! | 55 | | | 56 | | Important: | 57 | | * Must reconnect the TTP229 power so the mode changes will take effect | 58 | | * The 1 Megohm resistors already exist on some TTP229 modules | 59 | \******************************************************************************/ 60 | 61 | #if ARDUINO >= 100 62 | #include "Arduino.h" 63 | #else 64 | #include "WProgram.h" 65 | #endif 66 | 67 | #include "TTP229.h" 68 | 69 | TTP229::TTP229(uint8_t sclPin, uint8_t sdoPin) 70 | { 71 | _sclPin = sclPin; 72 | _sdoPin = sdoPin; 73 | 74 | pinMode(_sclPin , OUTPUT); 75 | pinMode(_sdoPin , INPUT); 76 | 77 | digitalWrite(_sclPin, HIGH); 78 | } 79 | 80 | uint8_t TTP229::ReadKey8() 81 | { 82 | WaitForTouch(); 83 | Key8(); 84 | return _key8; 85 | } 86 | uint8_t TTP229::GetKey8() 87 | { 88 | if (IsTouch()) Key8(); 89 | return _key8; 90 | } 91 | uint8_t TTP229::ReadKeys8() 92 | { 93 | WaitForTouch(); 94 | Keys8(); 95 | return _keys8; 96 | } 97 | uint8_t TTP229::GetKeys8() 98 | { 99 | if (IsTouch()) Keys8(); 100 | return _keys8; 101 | } 102 | uint8_t TTP229::ReadKey16() 103 | { 104 | WaitForTouch(); 105 | Key16(); 106 | return _key16; 107 | } 108 | uint8_t TTP229::GetKey16() 109 | { 110 | if (IsTouch()) Key16(); 111 | return _key16; 112 | } 113 | uint16_t TTP229::ReadKeys16() 114 | { 115 | WaitForTouch(); 116 | Keys16(); 117 | return _keys16; 118 | } 119 | uint16_t TTP229::GetKeys16() 120 | { 121 | if (IsTouch()) Keys16(); 122 | return _keys16; 123 | } 124 | 125 | void TTP229::Key8() 126 | { 127 | _key8 = 0; 128 | for (uint8_t i = 0; i < 8; i++) 129 | if (GetBit()) _key8 = i + 1; 130 | delay(2); // Tout 131 | } 132 | void TTP229::Keys8() 133 | { 134 | _keys8 = 0; 135 | for (uint8_t i = 0; i < 8; i++) 136 | if (GetBit()) _keys8 |= 1 << i; 137 | delay(2); // Tout 138 | } 139 | void TTP229::Key16() 140 | { 141 | _key16 = 0; 142 | for (uint8_t i = 0; i < 16; i++) 143 | if (GetBit()) _key16 = i + 1; 144 | delay(2); // Tout 145 | } 146 | void TTP229::Keys16() 147 | { 148 | _keys16 = 0; 149 | for (uint8_t i = 0; i < 16; i++) 150 | if (GetBit()) _keys16 |= 1 << i; 151 | delay(2); // Tout 152 | } 153 | 154 | bool TTP229::GetBit() 155 | { 156 | digitalWrite(_sclPin, LOW); 157 | delayMicroseconds(2); // 500KHz 158 | bool retVal = !digitalRead(_sdoPin); 159 | digitalWrite(_sclPin, HIGH); 160 | delayMicroseconds(2); // 500KHz 161 | return retVal; 162 | } 163 | 164 | bool TTP229::IsTouch() 165 | { 166 | uint16_t timeout = 5000; // 50ms timeout 167 | while (digitalRead(_sdoPin)) // DV LOW 168 | { 169 | if (--timeout == 0) return false; 170 | delayMicroseconds(10); 171 | } 172 | while (!digitalRead(_sdoPin)) // DV HIGH 173 | { 174 | if (--timeout == 0) return false; 175 | delayMicroseconds(10); 176 | } 177 | delayMicroseconds(10); // Tw 178 | return true; 179 | } 180 | void TTP229::WaitForTouch() 181 | { 182 | while (digitalRead(_sdoPin)); // DV LOW 183 | while (!digitalRead(_sdoPin)); // DV HIGH 184 | delayMicroseconds(10); // Tw 185 | } -------------------------------------------------------------------------------- /TTP229/TTP229.h: -------------------------------------------------------------------------------- 1 | /*********************************** LICENCE **********************************\ 2 | | Copyright (c) 2014, A.E. TEC | 3 | | All rights reserved. | 4 | | | 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the following conditions are met: | 7 | | | 8 | | * Redistributions of source code must retain the above copyright notice, | 9 | | this list of conditions and the following disclaimer. | 10 | | * Redistributions in binary form must reproduce the above copyright notice, | 11 | | this list of conditions and the following disclaimer in the documentation | 12 | | and/or other materials provided with the distribution. | 13 | | | 14 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 18 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 | | POSSIBILITY OF SUCH DAMAGE. | 25 | \******************************************************************************/ 26 | /************************************ USES ************************************\ 27 | | This library designed to communicate with the TTP229 chip from an Arduino | 28 | | | 29 | | It works with a TTP229 (16-Channel Digital Touch Capacitive Switch Sensor) | 30 | | using the 2-wires serial interface protocol - only 2 arduino pins. | 31 | \******************************************************************************/ 32 | /*********************************** CIRCUIT **********************************\ 33 | | General: | 34 | | * TTP229 VCC to pin VCC | 35 | | * TTP229 GND to pin GND | 36 | | * TTP229 SCL to any pin you choose... | 37 | | * TTP229 SDO to any pin you choose... | 38 | | | 39 | | 16 Buttons Mode (else 8 Buttons Mode): | 40 | | * TTP229 TP2 to GND via 1 Megohm resistor! | 41 | | # Must use the ReadKey16, GetKeys16... else use the ReadKey8, GetKeys8... | 42 | | | 43 | | Multi Keys Mode (else Single key Mode): | 44 | | * TTP229 TP3 to GND via 1 Megohm resistor! | 45 | | * TTP229 TP4 to GND via 1 Megohm resistor! | 46 | | | 47 | | 64Hz Sampling Rate (else 8Hz Sampling Rate): | 48 | | * TTP229 TP5 to GND via 1 Megohm resistor! | 49 | | | 50 | | 2ms Wake Up Rate (else 4ms Wake Up Rate): | 51 | | * TTP229 TP6 to GND via 1 Megohm resistor! | 52 | | | 53 | | 60sec Key On Timeout (else No Key On Timeout): | 54 | | * TTP229 TP7 to GND via 1 Megohm resistor! | 55 | | | 56 | | Important: | 57 | | * Must reconnect the TTP229 power so the mode changes will take effect | 58 | | * The 1 Megohm resistors already exist on some TTP229 modules | 59 | \******************************************************************************/ 60 | 61 | #if ARDUINO >= 100 62 | #include "Arduino.h" 63 | #else 64 | #include "WProgram.h" 65 | #endif 66 | 67 | #ifndef TTP229_h 68 | #define TTP229_h 69 | 70 | class TTP229 71 | { 72 | public: 73 | TTP229(uint8_t sclPin, uint8_t sdoPin); 74 | uint8_t 75 | ReadKey8(), 76 | GetKey8(), 77 | ReadKeys8(), 78 | GetKeys8(), 79 | ReadKey16(), 80 | GetKey16(); 81 | uint16_t 82 | ReadKeys16(), 83 | GetKeys16(); 84 | private: 85 | void 86 | WaitForTouch(), 87 | Key8(), 88 | Keys8(), 89 | Key16(), 90 | Keys16(); 91 | bool 92 | IsTouch(), 93 | GetBit(); 94 | 95 | uint8_t _sclPin, _sdoPin; 96 | uint8_t _key8, _keys8, _key16; 97 | uint16_t _keys16; 98 | }; 99 | 100 | #endif 101 | 102 | 103 | -------------------------------------------------------------------------------- /TTP229/examples/Calculator/Calculator.ino: -------------------------------------------------------------------------------- 1 | /*********************************** LICENCE **********************************\ 2 | | Copyright (c) 2014, A.E. TEC | 3 | | All rights reserved. | 4 | | | 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the following conditions are met: | 7 | | | 8 | | * Redistributions of source code must retain the above copyright notice, | 9 | | this list of conditions and the following disclaimer. | 10 | | * Redistributions in binary form must reproduce the above copyright notice, | 11 | | this list of conditions and the following disclaimer in the documentation | 12 | | and/or other materials provided with the distribution. | 13 | | | 14 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 18 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 | | POSSIBILITY OF SUCH DAMAGE. | 25 | \******************************************************************************/ 26 | /************************************ USES ************************************\ 27 | | This sketch demonstrates the use of TTP229 Module, in 16 Buttons Mode. | 28 | | It displays the pressed number on the Terminal | 29 | | | 30 | | It works with a TTP229 (16-Channel Digital Touch Capacitive Switch Sensor) | 31 | | using the 2-wires serial interface protocol - only 2 arduino pins. | 32 | \******************************************************************************/ 33 | /*********************************** CIRCUIT **********************************\ 34 | | 16 Buttons Multi Keys Mode: | 35 | | * TTP229 VCC to pin VCC | 36 | | * TTP229 GND to pin GND | 37 | | * TTP229 SCL to pin 2 | 38 | | * TTP229 SDO to pin 3 | 39 | | * TTP229 TP2 to GND via 1 Megohm resistor! | 40 | | * TTP229 TP3 to GND via 1 Megohm resistor! | 41 | | * TTP229 TP4 to GND via 1 Megohm resistor! | 42 | | # See TTP229_Modes.jpg for help... | 43 | | | 44 | | Important: | 45 | | * Must reconnect the TTP229 power so the mode changes will take effect | 46 | | * The 1 Megohm resistors already exist on some TTP229 modules | 47 | \******************************************************************************/ 48 | 49 | #include 50 | 51 | const int SCL_PIN = 2; // The pin number of the clock pin. 52 | const int SDO_PIN = 3; // The pin number of the data pin. 53 | 54 | TTP229 ttp229(SCL_PIN, SDO_PIN); // TTP229(sclPin, sdoPin) 55 | 56 | void setup() 57 | { 58 | Serial.begin(115200); 59 | Serial.println("Start Touching Several Keys Simultaneously!"); 60 | } 61 | 62 | void loop() 63 | { 64 | uint8_t sum = 0; 65 | uint16_t keys = ttp229.ReadKeys16(); // Blocking 66 | 67 | for (uint8_t i = 0; i < 16; i++) 68 | if (keys & (1 << i)) 69 | sum += i + 1; 70 | 71 | Serial.println(sum); 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /TTP229/examples/KeyToSerial/KeyToSerial.ino: -------------------------------------------------------------------------------- 1 | /*********************************** LICENCE **********************************\ 2 | | Copyright (c) 2014, A.E. TEC | 3 | | All rights reserved. | 4 | | | 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the following conditions are met: | 7 | | | 8 | | * Redistributions of source code must retain the above copyright notice, | 9 | | this list of conditions and the following disclaimer. | 10 | | * Redistributions in binary form must reproduce the above copyright notice, | 11 | | this list of conditions and the following disclaimer in the documentation | 12 | | and/or other materials provided with the distribution. | 13 | | | 14 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 15 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | 18 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 | | POSSIBILITY OF SUCH DAMAGE. | 25 | \******************************************************************************/ 26 | /************************************ USES ************************************\ 27 | | This sketch demonstrates the use of TTP229 Module, in 16 Buttons Mode. | 28 | | It displays the pressed number on the Terminal | 29 | | | 30 | | It works with a TTP229 (16-Channel Digital Touch Capacitive Switch Sensor) | 31 | | using the 2-wires serial interface protocol - only 2 arduino pins. | 32 | \******************************************************************************/ 33 | /*********************************** CIRCUIT **********************************\ 34 | | 16 Buttons Mode: | 35 | | * TTP229 VCC to pin VCC | 36 | | * TTP229 GND to pin GND | 37 | | * TTP229 SCL to pin 2 | 38 | | * TTP229 SDO to pin 3 | 39 | | * TTP229 TP2 to GND via 1 Megohm resistor! | 40 | | # See TTP229_Modes.jpg for help... | 41 | | | 42 | | Important: | 43 | | * Must reconnect the TTP229 power so the mode changes will take effect | 44 | | * The 1 Megohm resistors already exist on some TTP229 modules | 45 | \******************************************************************************/ 46 | 47 | #include 48 | 49 | const int SCL_PIN = 2; // The pin number of the clock pin. 50 | const int SDO_PIN = 3; // The pin number of the data pin. 51 | 52 | TTP229 ttp229(SCL_PIN, SDO_PIN); // TTP229(sclPin, sdoPin) 53 | 54 | void setup() 55 | { 56 | Serial.begin(115200); 57 | Serial.println("Start Touching One Key At a Time!"); 58 | } 59 | 60 | void loop() 61 | { 62 | uint8_t key = ttp229.ReadKey16(); // Blocking 63 | if (key) Serial.println(key); 64 | 65 | // uint8_t key = ttp229.GetKey16(); // Non Blocking 66 | // Serial.println(key); 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /TTP229/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For TTP229 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | TTP229 KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | ReadKey8 KEYWORD2 14 | GetKey8 KEYWORD2 15 | ReadKeys8 KEYWORD2 16 | GetKeys8 KEYWORD2 17 | ReadKey16 KEYWORD2 18 | GetKey16 KEYWORD2 19 | ReadKeys16 KEYWORD2 20 | GetKeys16 KEYWORD2 21 | 22 | 23 | --------------------------------------------------------------------------------