1414Implementation Notes
1515--------------------
1616
17- **Hardware:**
18-
19-
2017**Software and Dependencies:**
2118
2219* Adafruit CircuitPython firmware for the supported boards:
23- https://github.com/adafruit/circuitpython/releases
20+ https://circuitpython.org/downloads
21+
2422"""
2523
2624__version__ = "0.0.0-auto.0"
3129
3230
3331def map_range (x , in_min , in_max , out_min , out_max ):
32+
3433 """
3534 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+
3740 :return: Returns value mapped to new range
3841 :rtype: float
42+
43+
3944 """
4045 mapped = (x - in_min ) * (out_max - out_min ) / (in_max - in_min ) + out_min
4146 if out_min <= out_max :
@@ -45,7 +50,42 @@ def map_range(x, in_min, in_max, out_min, out_max):
4550
4651class Touchscreen :
4752 """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+ """
4989
5090 def __init__ (
5191 self ,
@@ -56,29 +96,11 @@ def __init__(
5696 * ,
5797 x_resistance = None ,
5898 samples = 4 ,
59- z_threshhold = 10000 ,
99+ z_threshold = 10000 ,
60100 calibration = None ,
61101 size = None
62102 ):
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+
82104 self ._xm_pin = x1_pin
83105 self ._xp_pin = x2_pin
84106 self ._ym_pin = y1_pin
@@ -90,7 +112,7 @@ def __init__(
90112 calibration = ((0 , 65535 ), (0 , 65535 ))
91113 self ._calib = calibration
92114 self ._size = size
93- self ._zthresh = z_threshhold
115+ self ._zthresh = z_threshold
94116
95117 @property
96118 def touch_point (self ): # pylint: disable=too-many-locals
0 commit comments