使用下面的程序,可以将STM32F7DISC作为触摸板,控制PC上的鼠标移动。
import lcdF7D as lcd
import tchF7D as ts
from time import sleep_ms
lcd.init()
lcd.set_text_color(0x00FF00)
ts.init(480, 272)
m=pyb.USB_HID()
px, py = 0, 0
mx, my = 0, 0
def TouchPad(ts):
global px, py, mx ,my
while 1:
ts.get_state()
if ts.touches() > 0:
lcd.clear(0)
#print('\nTouch num: ', ts.touches(), ts.point_info(1))
p = ts.point_info(1)
x1 = max(min(p[0] - p[2]//2, 479), 0)
x2 = max(min(p[0] + p[2]//2, 479), 0)
y1 = max(min(p[1] - p[2]//2, 271), 0)
y2 = max(min(p[1] + p[2]//2, 271), 0)
lcd.set_text_color(0x00FF00)
lcd.draw_rect(x1, y1, x2-x1, y2-y1)
if px != 10000:
mx = p[0] - px
my = p[1] - py
px, py = p[0], p[1]
m.send((0, mx, my, 0))
print(mx, my)
else:
px = 10000
sleep_ms(20)
TouchPad(ts)
注意在运行前需要先在 boot.py,将USB模式改为 VCP+HID
此内容由EEWORLD论坛网友dcexpert原创,如需转载或用于商业用途需征得作者同意并注明出处