1 Star 0 Fork 0

zlf017/LCD-show1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Mouse_Key.py 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
goodtft 提交于 2021-01-27 08:18 . add 1.54 IPS driver
from pymouse import PyMouse
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
btn_up = 5
btn_down = 26
btn_left = 19
btn_right = 6
btn_key1 = 21
btn_key2 = 20
# Up, Down, left, right, Button
GPIO.setup(btn_up, GPIO.IN,GPIO.PUD_UP)
GPIO.setup(btn_down, GPIO.IN,GPIO.PUD_UP)
GPIO.setup(btn_left, GPIO.IN,GPIO.PUD_UP)
GPIO.setup(btn_right, GPIO.IN,GPIO.PUD_UP)
GPIO.setup(btn_key1, GPIO.IN,GPIO.PUD_UP)
GPIO.setup(btn_key2, GPIO.IN,GPIO.PUD_UP)
def main():
m = PyMouse()
KEY1_flag = False
KEY2_flag = False
KEY3_flag = False
while True:
nowxy = m.position()
if (not GPIO.input(btn_key1)): # button pressed
KEY1_flag = True
print("KEY1")
m.click(nowxy[0], nowxy[1], 1)
if KEY1_flag and GPIO.input(btn_key1): # button released
KEY1_flag = False
if (not GPIO.input(btn_key2)): # button pressed
KEY2_flag = True
print("KEY1")
m.click(nowxy[0], nowxy[1], 2)
if KEY2_flag and GPIO.input(btn_key2): # button released
KEY2_flag = False
if (not GPIO.input(btn_up)): # button pressed
m.move(nowxy[0] - 5, nowxy[1])
if (not GPIO.input(btn_down)): # button pressed
m.move(nowxy[0] + 5, nowxy[1])
if (not GPIO.input(btn_left)): # button pressed
m.move(nowxy[0], nowxy[1] + 5)
if (not GPIO.input(btn_right)): # button pressed
m.move(nowxy[0], nowxy[1] - 5)
time.sleep(0.02) # Poll every 20ms (otherwise CPU load gets too high)
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zlf017/LCD-show1.git
git@gitee.com:zlf017/LCD-show1.git
zlf017
LCD-show1
LCD-show1
master

搜索帮助