5. MixPY_ Touch screen function library
The touchscreen module contains basic touchscreen reading operations (import touchscreen as ts).
(1) Initialize the touch screen
ts.init(i2c=None, cal=None)
Initialize the touch screen
Parameters:
i2c: Touch screen that supports I2C communication, pass in the I2C instance object, this parameter may be renamed or cancelled later
cal: calibration data, a tuple of 7 integer values, which can be obtained through the touchscreen.calibrate() function
Returns:
None
(2) Calibrate the screen
ts.calibrate()
Calibrate the screen so that the screen display and touch screen pixels can correspond
Parameters:
None
Return:
Returns a tuple of 7 integer values, which can be saved to the file system or flash and passed in during initialization so that you don't have to calibrate every time
(3) Obtaining touch data
ts.read()
Read the current screen status and the coordinates of the pressed point
Parameters:
None
Returns:
a tuple of 3 integer values (status, x, y). Note that this value will always maintain the previous status
status: status, the values are touchscreen.STATUS_PRESS, touchscreen.STATUS_MOVE, touchscreen.STATUS_RELEASE
x: x-axis coordinate
y: y-axis coordinate
(4) System default touchscreen constants:
touchscreen.STATUS\_PRESS
The screen is pressed, the first value of the tuple returned by the read() function
touchscreen.STATUS\_MOVE
The screen is pressed and moved, that is, pressed and moved, the first value of the tuple returned by the read() function
touchscreen.STATUS\_RELEASE
The screen is no longer held down, that is, there is no click, and the read() function returns the first value of the tuple.
|