54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Basic usage example for the PyFT5xx6 library.
|
|
This example demonstrates how to use the FT5316 touch controller in polling mode.
|
|
"""
|
|
|
|
from pyft5xx6 import FT5316, Status, Mode, Gestures
|
|
import time
|
|
|
|
def main():
|
|
# Initialize the touch controller
|
|
touch = FT5316()
|
|
result = touch.begin(i2c_bus=1) # Using I2C bus 1
|
|
|
|
if result != Status.NOMINAL:
|
|
print("Failed to initialize touch controller")
|
|
return
|
|
|
|
# Set polling mode
|
|
touch.set_mode(Mode.POLLING)
|
|
|
|
print("Touch controller initialized. Touch the screen...")
|
|
|
|
# Allocate a buffer for 10 touch records
|
|
touch.use_buffer(10)
|
|
|
|
# Main loop
|
|
try:
|
|
while True:
|
|
# Update touch data
|
|
touch.update()
|
|
|
|
# Check if there is a new touch event
|
|
if touch.new_touch:
|
|
record = touch.read()
|
|
print(f"Number of touches: {record.num_touches}")
|
|
|
|
if record.num_touches > 0:
|
|
print(f"Touch 1: ({record.t1x}, {record.t1y})")
|
|
|
|
if record.num_touches > 1:
|
|
print(f"Touch 2: ({record.t2x}, {record.t2y})")
|
|
|
|
if record.gesture != Gestures.NO_GESTURE:
|
|
print(f"Gesture: {record.gesture.name}")
|
|
|
|
time.sleep(0.01) # 10ms delay
|
|
|
|
except KeyboardInterrupt:
|
|
print("Exiting")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|