Mechatronics
Documentation for ME 405 labs
drivers.TouchPanel.TouchPanel Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
x_mA pyb.Pin object connected to x-. This object must be connected to an analog adc.
x_pA pyb.Pin object connected to x+. This object must be connected to an analog adc.
y_mA pyb.Pin object connected to y-.
y_pA pyb.Pin object connected to y+. This object must be connected to an analog adc.
widthOptionally set the width by measuring the difference in adc counts across the touch panel.
lengthOptionally set the length by measuring the difference in adc counts across the touch panel.
originOptionally set the geometric origin by providing an [x, y] coordinate offset (as measured in adc counts).

Member Function Documentation

◆ get_x()

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.

Returns
Returns the x-coordinate in mm of the current touch. If the panel is not being touched then the value returned is unspecified.

◆ get_y()

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.

Returns
Returns the y-coordinate in mm of the current touch. If the panel is not being touched then the value returned is unspecified.

◆ has_contact()

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.

Returns
Returns the true if the panel is being touched, otherwise false.

◆ scan()

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
Returns
Returns a tuple of [x, y, z] where x and y are coordinates in mm and z is a boolean value dictating if the panel is currently being touched.

The documentation for this class was generated from the following file: