├── .gitattributes
├── .github
└── workflows
│ └── sync_issues.yml
├── .gitignore
├── .gitlab-ci.yml
├── .travis.yml
├── License.txt
├── README.md
├── SeeedTouchScreen.cpp
├── SeeedTouchScreen.h
├── examples
└── touchScreen
│ └── touchScreen.ino
├── keywords.txt
└── library.properties
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.github/workflows/sync_issues.yml:
--------------------------------------------------------------------------------
1 | name: Automate Issue Management
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - edited
8 | - assigned
9 | - unassigned
10 | - labeled
11 | - unlabeled
12 | - reopened
13 |
14 | jobs:
15 | add_issue_to_project:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Add issue to GitHub Project
19 | uses: actions/add-to-project@v1.0.2
20 | with:
21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17
22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }}
23 | labeled: bug
24 | label-operator: NOT
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | build:
2 | tags:
3 | - nas
4 | script:
5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
6 | - chmod +x seeed-arduino-ci.sh
7 | - bash $PWD/seeed-arduino-ci.sh test
8 |
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 |
2 | language: generic
3 | dist: bionic
4 | sudo: false
5 | cache:
6 | directories:
7 | - ~/arduino_ide
8 | - ~/.arduino15/packages/
9 |
10 | before_install:
11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
12 |
13 | script:
14 | - chmod +x seeed-arduino-ci.sh
15 | - cat $PWD/seeed-arduino-ci.sh
16 | - bash $PWD/seeed-arduino-ci.sh test
17 |
18 | notifications:
19 | email:
20 | on_success: change
21 | on_failure: change
22 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Seeed Technology Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Touch Screen Driver [](https://travis-ci.com/Seeed-Studio/Touch_Screen_Driver)
2 | ---------------------------------------------------------
3 |
4 | 
5 |
6 | [2.8 TFT Touch Shield V2.0](https://www.seeedstudio.com/28-tft-touch-shield-v20-p-1286.html?cPath=34_36)
7 |
8 | This is a multifunctional Arduino/Seeeduino/Arduino Mega compatible resistive touch screen. It can be used as display device or sketch pad.Compared with the previous version, 2.8’’TFT Touch Shield V1.0 , we replaced the screen driver with a more professional chip, ILI9341 driver, providing different pin-saving SPI communication without sacrificing the data transmitting speed. Due to the communication method change, programs developed for the original version need modifications before being transplanted to the new version. With a SD card module integrated also on this shield, this shield reserves great room for other expansions to your project.
9 |
10 |
11 | **Features**
12 |
13 | - Big screen for easy and comfortable experience
14 | - Backlight controllable via programming
15 | - 65535 rich colors display
16 | - SPI pin-saving communication method
17 | - Full screen touch active range
18 |
19 |
20 |
21 | ##Usage
22 |
23 | This is a driver library for Tft Touch Shield.
24 |
25 | For more information, please refer to [wiki](http://www.seeedstudio.com/wiki/2.8%27%27_TFT_Touch_Shield_v2.0).
26 |
27 |
28 | ----
29 |
30 |
31 | This software is written by loovee [luweicong@seeedstudio.com](luweicong@seeedstudio.com "luweicong@seeedstudio.com") for seeed studio
32 | and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
33 |
34 | Contributing to this software is warmly welcomed. You can do this basically by
35 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
36 | for operating guide). Adding change log and your contact into file header is encouraged.
37 | Thanks for your contribution.
38 |
39 | Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
40 | Benefiting from local manufacture power and convenient global logistic system,
41 | we integrate resources to serve new era of innovation. Seeed also works with
42 | global distributors and partners to push open hardware movement.
43 |
44 |
45 |
46 |
47 |
48 | [](https://github.com/igrigorik/ga-beacon)
49 |
--------------------------------------------------------------------------------
/SeeedTouchScreen.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | SeeedTouchScreen.cpp - Library for 4-line resistance touch screen.
3 | Modified by loovee Aug 12, 2012.
4 | (c) ladyada / adafruit
5 | Code under MIT License.
6 | */
7 |
8 | #include "pins_arduino.h"
9 | #include "wiring_private.h"
10 |
11 | #if (defined(__AVR__) || defined(__SAMD21G18A__))
12 | #include
13 | #else
14 | #include
15 | #endif
16 | #include "SeeedTouchScreen.h"
17 |
18 | // increase or decrease the touchscreen oversampling. This is a little different than you make think:
19 | // 1 is no oversampling, whatever data we get is immediately returned
20 | // 2 is double-sampling and we only return valid data if both points are the same
21 | // 3+ uses insert sort to get the median value.
22 | // We found 2 is precise yet not too slow so we suggest sticking with it!
23 |
24 | #define NUMSAMPLES 2 // sample number
25 | #define COMP 2
26 | #define AVERAGE 1
27 | #define RXPLATE 300
28 | #define TSDEBUG 0 // if print the debug information
29 | Point::Point(void) {
30 | x = y = 0;
31 | }
32 |
33 | Point::Point(int x0, int y0, int z0) {
34 | x = x0;
35 | y = y0;
36 | z = z0;
37 | }
38 |
39 | bool Point::operator==(Point p1) {
40 | return ((p1.x == x) && (p1.y == y) && (p1.z == z));
41 | }
42 |
43 | bool Point::operator!=(Point p1) {
44 | return ((p1.x != x) || (p1.y != y) || (p1.z != z));
45 | }
46 |
47 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) {
48 | _yp = yp;
49 | _xm = xm;
50 | _ym = ym;
51 | _xp = xp;
52 | }
53 |
54 | #if AVERAGE
55 | #define AVERAGETIME 4
56 | int avr_analog(int adpin) {
57 | int sum = 0;
58 | int max = 0;
59 | int min = 1024;
60 | for (int i = 0; i < AVERAGETIME; i++) {
61 | int tmp = analogRead(adpin);
62 | if (tmp > max) {
63 | max = tmp;
64 | }
65 | if (tmp < min) {
66 | min = tmp;
67 | }
68 | sum += tmp;
69 | // sum+=analogRead(adpin);
70 | }
71 | return (sum - min - max) / (AVERAGETIME - 2);
72 |
73 | }
74 | #endif
75 |
76 | Point TouchScreen::getPoint(void) {
77 | int x, y, z = 1;
78 | int samples[NUMSAMPLES];
79 | #if TSDEBUG
80 | int xx[2] = {0, 0};
81 | int yy[2] = {0, 0};
82 | #endif
83 | uint8_t i, valid;
84 |
85 | uint8_t xp_port = digitalPinToPort(_xp);
86 | unsigned char yp_port = digitalPinToPort(_yp);
87 | unsigned char xm_port = digitalPinToPort(_xm);
88 | unsigned char ym_port = digitalPinToPort(_ym);
89 |
90 | unsigned char xp_pin = digitalPinToBitMask(_xp);
91 | unsigned char yp_pin = digitalPinToBitMask(_yp);
92 | unsigned char xm_pin = digitalPinToBitMask(_xm);
93 | unsigned char ym_pin = digitalPinToBitMask(_ym);
94 | valid = 1;
95 | pinMode(_yp, INPUT);
96 | pinMode(_ym, INPUT);
97 |
98 | *portOutputRegister(yp_port) &= ~yp_pin;
99 | *portOutputRegister(ym_port) &= ~ym_pin;
100 |
101 | pinMode(_xp, OUTPUT);
102 | pinMode(_xm, OUTPUT);
103 |
104 | *portOutputRegister(xp_port) |= xp_pin;
105 | *portOutputRegister(xm_port) &= ~xm_pin;
106 |
107 | for (i = 0; i < NUMSAMPLES; i++) {
108 | #if AVERAGE
109 | samples[i] = avr_analog(_yp);
110 | #else
111 | samples[i] = analogRead(_yp);
112 | #endif
113 |
114 | #if TSDEBUG
115 | xx[i] = samples[i];
116 | #endif
117 | }
118 |
119 | #if !COMP
120 | if (samples[0] != samples[1]) {
121 | valid = 0;
122 | }
123 | #else
124 | int icomp = samples[0] > samples[1] ? samples[0] - samples[1] : samples[1] - samples[0];
125 | if (icomp > COMP) {
126 | valid = 0;
127 | }
128 | #endif
129 |
130 | x = (samples[0] + samples[1]);
131 |
132 | pinMode(_xp, INPUT);
133 | pinMode(_xm, INPUT);
134 | *portOutputRegister(xp_port) &= ~xp_pin;
135 |
136 | pinMode(_yp, OUTPUT);
137 | *portOutputRegister(yp_port) |= yp_pin;
138 | pinMode(_ym, OUTPUT);
139 |
140 | for (i = 0; i < NUMSAMPLES; i++) {
141 | #if AVERAGE
142 | samples[i] = avr_analog(_xm);
143 | #else
144 | samples[i] = analogRead(_xm);
145 | #endif
146 | #if TSDEBUG
147 | yy[i] = samples[i];
148 | #endif
149 | }
150 |
151 | #if !COMP
152 | if (samples[0] != samples[1]) {
153 | valid = 0;
154 | }
155 | #else
156 | icomp = samples[0] > samples[1] ? samples[0] - samples[1] : samples[1] - samples[0];
157 | if (icomp > COMP) {
158 | valid = 0;
159 | }
160 | #endif
161 | y = (samples[0] + samples[0]);
162 |
163 | pinMode(_xp, OUTPUT);
164 | *portOutputRegister(xp_port) &= ~xp_pin; // Set X+ to ground
165 | *portOutputRegister(ym_port) |= ym_pin; // Set Y- to VCC
166 | *portOutputRegister(yp_port) &= ~yp_pin; // Hi-Z X- and Y+
167 | pinMode(_yp, INPUT);
168 |
169 | int z1 = analogRead(_xm);
170 | int z2 = analogRead(_yp);
171 | float rtouch = 0;
172 |
173 | rtouch = z2;
174 | rtouch /= z1;
175 | rtouch -= 1;
176 | rtouch *= (2046 - x) / 2;
177 | rtouch *= RXPLATE;
178 | rtouch /= 1024;
179 | z = rtouch;
180 | if (! valid) {
181 | z = 0;
182 | }
183 |
184 | #if TSDEBUG
185 | if (z > __PRESSURE) {
186 | Serial.print("x1 = "); Serial.print(xx[0]);
187 | Serial.print("\tx2 = "); Serial.print(xx[1]);
188 | Serial.print("\ty2 = "); Serial.print(yy[0]);
189 | Serial.print("\ty2 = "); Serial.println(yy[1]);
190 | }
191 | #endif
192 |
193 | return Point(x, y, z);
194 | }
195 |
196 | bool TouchScreen::isTouching(void) {
197 | Point p = getPoint();
198 | if (p.z > __PRESSURE) {
199 | return 1;
200 | } else {
201 | return 0;
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/SeeedTouchScreen.h:
--------------------------------------------------------------------------------
1 | /*
2 | SeeedTouchScreen.h - Library for 4-line resistance touch screen.
3 | Modified by loovee Aug 12, 2012.
4 | (c) ladyada / adafruit
5 | Code under MIT License.
6 | */
7 | #define __PRESSURE 10
8 | #define __PRESURE __PRESSURE // Previous misspelled macro left for backwards compatibility
9 | class Point {
10 | public:
11 | int x, y, z;
12 |
13 | public:
14 | Point(void);
15 | Point(int x, int y, int z);
16 | bool operator==(Point);
17 | bool operator!=(Point);
18 |
19 | };
20 |
21 | class TouchScreen {
22 | private:
23 | unsigned char _yp, _ym, _xm, _xp;
24 |
25 | public:
26 | TouchScreen(unsigned char xp, unsigned char yp, unsigned char xm, unsigned char ym);
27 | bool isTouching(void);
28 | Point getPoint();
29 |
30 | };
31 |
--------------------------------------------------------------------------------
/examples/touchScreen/touchScreen.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // mega
5 | #define YP A2 // must be an analog pin, use "An" notation!
6 | #define XM A1 // must be an analog pin, use "An" notation!
7 | #define YM 54 // can be a digital pin, this is A0
8 | #define XP 57 // can be a digital pin, this is A3
9 |
10 | #elif defined(__AVR_ATmega32U4__) // leonardo
11 | #define YP A2 // must be an analog pin, use "An" notation!
12 | #define XM A1 // must be an analog pin, use "An" notation!
13 | #define YM 18 // can be a digital pin, this is A0
14 | #define XP 21 // can be a digital pin, this is A3
15 |
16 | #else //168, 328, something else
17 | #define YP A2 // must be an analog pin, use "An" notation!
18 | #define XM A1 // must be an analog pin, use "An" notation!
19 | #define YM 14 // can be a digital pin, this is A0
20 | #define XP 17 // can be a digital pin, this is A3
21 |
22 | #endif
23 |
24 | //Measured ADC values for (0,0) and (210-1,320-1)
25 | //TS_MINX corresponds to ADC value when X = 0
26 | //TS_MINY corresponds to ADC value when Y = 0
27 | //TS_MAXX corresponds to ADC value when X = 240 -1
28 | //TS_MAXY corresponds to ADC value when Y = 320 -1
29 |
30 | #define TS_MINX 116*2
31 | #define TS_MAXX 890*2
32 | #define TS_MINY 83*2
33 | #define TS_MAXY 913*2
34 |
35 |
36 | // For better pressure precision, we need to know the resistance
37 | // between X+ and X- Use any multimeter to read it
38 | // The 2.8" TFT Touch shield has 300 ohms across the X plate
39 | TouchScreen ts = TouchScreen(XP, YP, XM, YM);
40 |
41 | void setup(void) {
42 | Serial.begin(9600);
43 | }
44 |
45 | void loop(void) {
46 | // a point object holds x y and z coordinates
47 | Point p = ts.getPoint();
48 |
49 | if (p.z > __PRESSURE) {
50 | Serial.print("Raw X = "); Serial.print(p.x);
51 | Serial.print("\tRaw Y = "); Serial.print(p.y);
52 | Serial.print("\tPressure = "); Serial.println(p.z);
53 | }
54 |
55 |
56 | p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
57 | p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
58 |
59 | // we have some minimum pressure we consider 'valid'
60 | // pressure of 0 means no pressing!
61 | if (p.z > __PRESSURE) {
62 | Serial.print("X = "); Serial.print(p.x);
63 | Serial.print("\tY = "); Serial.print(p.y);
64 | Serial.print("\tPressure = "); Serial.println(p.z);
65 | }
66 |
67 | delay(100);
68 | }
69 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map For SeeedTouchScreen
3 | #######################################
4 |
5 | #######################################
6 | # Datatypes (KEYWORD1)
7 | #######################################
8 | Point KEYWORD1
9 | TouchScreen KEYWORD1
10 | SeeedTouchScreen KEYWORD1
11 | #######################################
12 | # Methods and Functions (KEYWORD2)
13 | #######################################
14 | TouchScreen KEYWORD2
15 | isTouching KEYWORD2
16 | getPoint KEYWORD2
17 |
18 | #######################################
19 | # Constants (LITERAL1)
20 | #######################################
21 | __PRESSURE LITERAL1
22 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=Touch Screen Driver
2 | version=1.0.0
3 | author=Seeed Studio
4 | maintainer=Seeed Studio
5 | sentence=Arduino library for Touch Screen Driver.
6 | paragraph=Arduino library for Touch Screen Driver.
7 | category=Sensors
8 | url=https://github.com/Seeed-Studio/Touch_Screen_Driver
9 | architectures=*
--------------------------------------------------------------------------------