14
14
Implementation Notes
15
15
--------------------
16
16
17
- **Hardware:**
18
-
19
-
20
17
**Software and Dependencies:**
21
18
22
19
* Adafruit CircuitPython firmware for the supported boards:
23
- https://github.com/adafruit/circuitpython/releases
20
+ https://circuitpython.org/downloads
21
+
24
22
"""
25
23
26
24
__version__ = "0.0.0-auto.0"
31
29
32
30
33
31
def map_range (x , in_min , in_max , out_min , out_max ):
32
+
34
33
"""
35
34
Maps a number from one range to another.
36
- Note: This implementation handles values < in_min differently than arduino's map function does.
35
+
36
+ .. note:: This implementation handles values < in_min differently
37
+ than arduino's map function does.
38
+
39
+
37
40
:return: Returns value mapped to new range
38
41
:rtype: float
42
+
43
+
39
44
"""
40
45
mapped = (x - in_min ) * (out_max - out_min ) / (in_max - in_min ) + out_min
41
46
if out_min <= out_max :
@@ -45,7 +50,42 @@ def map_range(x, in_min, in_max, out_min, out_max):
45
50
46
51
class Touchscreen :
47
52
"""A driver for common and inexpensive resistive touchscreens. Analog input
48
- capable pins are required to read the intrinsic potentiometers"""
53
+ capable pins are required to read the intrinsic potentiometers
54
+
55
+ Create the Touchscreen object. At a minimum you need the 4 pins
56
+ that will connect to the 4 contacts on a screen. X and Y are just our
57
+ names, you can rotate and flip the data if you like. All pins must be
58
+ capable of becoming DigitalInOut pins. :attr:`y2_pin`, :attr:`x1_pin`
59
+ and :attr:`x2_pin` must also be capable of becoming AnalogIn pins.
60
+ If you know the resistance across the x1 and x2 pins when not touched,
61
+ pass that in as 'x_resistance'.
62
+ :attr:`calibration` is a tuple of two tuples, the default is
63
+ ((0, 65535), (0, 65535)). The numbers are the min/max readings for the
64
+ X and Y coordinate planes, respectively. To figure these out, pass in
65
+ no calibration value and read the raw values out while touching the
66
+ panel.
67
+ :attr:`size` is a tuple that gives the X and Y pixel size of the underlying
68
+ screen. If passed in, we will automatically scale/rotate so touches
69
+ correspond to the graphical coordinate system.
70
+
71
+ :param ~microcontroller.Pin x1_pin: Data pin for Left side of the screen.
72
+ Must also be capable of becoming AnalogIn pins.
73
+ :param ~microcontroller.Pin x2_pin: Data pin for Right side of the screen.
74
+ Must also be capable of becoming AnalogIn pins.
75
+ :param ~microcontroller.Pin y1_pin: Data pin for Bottom side of the screen.
76
+ :param ~microcontroller.Pin y2_pin: Data pin for Top side of the screen.
77
+ Must also be capable of becoming AnalogIn pins.
78
+ :param int x_resistance: If you know the resistance across the x1 and x2
79
+ pins when not touched, pass that in as :attr:`x_resistance`
80
+ :param int samples: change by adjusting :attr:`samples` arg. Defaults to :const:`4`
81
+ :param int z_threshold: We can also detect the 'z' threshold, how much
82
+ its pressed. We don't register a touch unless its higher than :attr:`z_threshold`
83
+ :param (int,int),(int,int) calibration: A tuple of two tuples The numbers are the min/max
84
+ readings for the X and Y coordinate planes, respectively.
85
+ Defaults to :const:`((0, 65535), (0, 65535))`
86
+ :param int,int size: The dimensions of the screen as (x, y).
87
+
88
+ """
49
89
50
90
def __init__ (
51
91
self ,
@@ -56,29 +96,11 @@ def __init__(
56
96
* ,
57
97
x_resistance = None ,
58
98
samples = 4 ,
59
- z_threshhold = 10000 ,
99
+ z_threshold = 10000 ,
60
100
calibration = None ,
61
101
size = None
62
102
):
63
- """Create the Touchscreen object. At a minimum you need the 4 pins
64
- that will connect to the 4 contacts on a screen. X and Y are just our
65
- names, you can rotate and flip the data if you like. All pins must be
66
- capable of becoming DigitalInOut pins. 'y2_pin', 'x1_pin' and 'x2_pin'
67
- must also be capable of becoming AnalogIn pins.
68
- If you know the resistance across the x1 and x2 pins when not touched,
69
- pass that in as 'x_resistance'.
70
- By default we oversample 4 times, change by adjusting 'samples' arg.
71
- We can also detect the 'z' threshold, how much its prssed. We don't
72
- register a touch unless its higher than 'z_threshold'
73
- 'calibration' is a tuple of two tuples, the default is
74
- ((0, 65535), (0, 65535)). The numbers are the min/max readings for the
75
- X and Y coordinate planes, respectively. To figure these out, pass in
76
- no calibration value and read the raw values out while touching the
77
- panel.
78
- 'size' is a tuple that gives the X and Y pixel size of the underlying
79
- screen. If passed in, we will automatically scale/rotate so touches
80
- correspond to the graphical coordinate system.
81
- """
103
+
82
104
self ._xm_pin = x1_pin
83
105
self ._xp_pin = x2_pin
84
106
self ._ym_pin = y1_pin
@@ -90,7 +112,7 @@ def __init__(
90
112
calibration = ((0 , 65535 ), (0 , 65535 ))
91
113
self ._calib = calibration
92
114
self ._size = size
93
- self ._zthresh = z_threshhold
115
+ self ._zthresh = z_threshold
94
116
95
117
@property
96
118
def touch_point (self ): # pylint: disable=too-many-locals
0 commit comments