A class for collecting information from the touch panel over I2C. More...
Public Member Functions | |
| def | __init__ (self, x_m, x_p, y_m, y_p, width=None, length=None, origin=INTERCEPT) |
| Initialize a TouchPanel driver object. More... | |
| def | get_x (self) |
| Get the x-coordinate of the current touch. More... | |
| def | get_y (self) |
| Get the y-coordinate of the current touch. More... | |
| def | has_contact (self) |
| Detect if the touch panel is currently being touched. More... | |
| def | scan (self) |
| Scan the touch panel to detect for contact (z coordinate) and x and y position. More... | |
Public Attributes | |
| x_m | |
| x- pin | |
| x_p | |
| x+ pin | |
| y_m | |
| y- pin | |
| y_p | |
| y+ pin | |
| slope | |
| Slopes used for linear calculation of position. | |
| origin | |
| Origin used for linear calculation of position. | |
A class for collecting information from the touch panel over I2C.
This class can be used to get X and Y positions as well as scan for contact.
| def drivers.TouchPanel.TouchPanel.__init__ | ( | self, | |
| x_m, | |||
| x_p, | |||
| y_m, | |||
| y_p, | |||
width = None, |
|||
length = None, |
|||
origin = INTERCEPT |
|||
| ) |
Initialize a TouchPanel driver object.
This object expects the pins connected to +/-x and +/-y. Optionally a width, length, and origin can be specified in order use this class with a different sized touch panel than provided on the ME 405 test bench, or to tune where the exact center is. Note that the physical dimensions are always assumed to be 176mm x 100mm.
| x_m | A pyb.Pin object connected to x-. This object must be connected to an analog adc. |
| x_p | A pyb.Pin object connected to x+. This object must be connected to an analog adc. |
| y_m | A pyb.Pin object connected to y-. |
| y_p | A pyb.Pin object connected to y+. This object must be connected to an analog adc. |
| width | Optionally set the width by measuring the difference in adc counts across the touch panel. |
| length | Optionally set the length by measuring the difference in adc counts across the touch panel. |
| origin | Optionally set the geometric origin by providing an [x, y] coordinate offset (as measured in adc counts). |
| def drivers.TouchPanel.TouchPanel.get_x | ( | self | ) |
Get the x-coordinate of the current touch.
Sets x- pin to low, x+ pin to high, floats the y+ pin, and takes an analog measurement of the y- pin. Pins are left in this mode upon exit.
| def drivers.TouchPanel.TouchPanel.get_y | ( | self | ) |
Get the y-coordinate of the current touch.
Sets y- pin to low, y+ pin to high, floats the x- pin, and takes an analog measurement of the x+ pin. Pins are left in this mode upon exit.
| def drivers.TouchPanel.TouchPanel.has_contact | ( | self | ) |
Detect if the touch panel is currently being touched.
Sets y- pin to high, x- pin to low, floats the y- and pin, and takes an analog measurement of the x+ pin. Pins are left in this mode upon exit. Checks to see if the measured voltage is higher than LOW_THRESHOLD.
| def drivers.TouchPanel.TouchPanel.scan | ( | self | ) |
Scan the touch panel to detect for contact (z coordinate) and x and y position.
Scans x, z, then y coordinates, taking advantage of pin mode settings for a faster read time than scanning each individually. If the panel is not being touched then the values for x and y position returned are meaningless. Results of timing tests using test_TouchPanel-timing.py :
| method | average time (µs) |
| get_x | 330 |
| get_y | 330 |
| has_contact | 295 |
| scan | 660 |