触摸
触摸功能是STM32F7DISC开发板的另一个特点,支持最多5点检测。在这个版本的micropython中,我们可以这样使用它:
import lcdF7D as lcd
import tchF7D as ts
from time import sleep_ms
lcd.init()
lcd.set_text_color(0x00FF00)
ts.init(480, 272)
def ts_test():
while 1:
ts.get_state()
if ts.touches() > 0:
lcd.clear(0)
print('\nTouch num: ', str(ts.touches()))
for i in range(ts.touches()):
print(' {} {}'.format(i+1, ts.point_info(i+1)))
p = ts.point_info(i+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)
sleep_ms(100)
运行效果
此内容由EEWORLD论坛网友dcexpert原创,如需转载或用于商业用途需征得作者同意并注明出处