Linduino
1.3.0
Linear Technology Arduino-Compatible Demonstration Board
touchScreen.ino
Go to the documentation of this file.
1
#include <stdint.h>
2
#include <
SeeedTouchScreen.h
>
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
{
43
Serial.begin(9600);
44
}
45
46
void
loop
(
void
)
47
{
48
// a point object holds x y and z coordinates
49
Point
p = ts.
getPoint
();
50
51
if
(p.
z
>
__PRESURE
)
52
{
53
Serial.print(
"Raw X = "
);
54
Serial.print(p.
x
);
55
Serial.print(
"\tRaw Y = "
);
56
Serial.print(p.
y
);
57
Serial.print(
"\tPressure = "
);
58
Serial.println(p.
z
);
59
}
60
61
62
p.
x
= map(p.
x
,
TS_MINX
,
TS_MAXX
, 0, 240);
63
p.
y
= map(p.
y
,
TS_MINY
,
TS_MAXY
, 0, 320);
64
65
// we have some minimum pressure we consider 'valid'
66
// pressure of 0 means no pressing!
67
if
(p.
z
>
__PRESURE
)
68
{
69
Serial.print(
"X = "
);
70
Serial.print(p.
x
);
71
Serial.print(
"\tY = "
);
72
Serial.print(p.
y
);
73
Serial.print(
"\tPressure = "
);
74
Serial.println(p.
z
);
75
}
76
77
delay(100);
78
}
TS_MAXX
#define TS_MAXX
Definition:
touchScreen.ino:31
TS_MAXY
#define TS_MAXY
Definition:
touchScreen.ino:33
XP
#define XP
Definition:
touchScreen.ino:20
__PRESURE
#define __PRESURE
Definition:
SeeedTouchScreen.h:7
YM
#define YM
Definition:
touchScreen.ino:19
Point::x
int x
Definition:
SeeedTouchScreen.h:11
Point
Definition:
SeeedTouchScreen.h:8
XM
#define XM
Definition:
touchScreen.ino:18
Point::z
int z
Definition:
SeeedTouchScreen.h:11
Point::y
int y
Definition:
SeeedTouchScreen.h:11
TouchScreen::getPoint
Point getPoint()
Definition:
SeeedTouchScreen.cpp:74
loop
static void loop(void)
Definition:
touchScreen.ino:46
TS_MINY
#define TS_MINY
Definition:
touchScreen.ino:32
ts
TouchScreen ts
Definition:
touchScreen.ino:39
YP
#define YP
Definition:
touchScreen.ino:17
TS_MINX
#define TS_MINX
Definition:
touchScreen.ino:30
TouchScreen
Definition:
SeeedTouchScreen.h:21
SeeedTouchScreen.h
setup
static void setup(void)
Definition:
touchScreen.ino:41
LTSketchbook
libraries
SeeedTouchScreen
examples
touchScreen
touchScreen.ino
Generated on Thu Mar 19 2020 10:59:37 for Linduino by
1.8.13