注意,摄像头和这里的IO有冲突,要自己查阅原理图,找到一些不被其他设备用的作为按键的输入口。用飞线飞到矩阵键盘里面。
# Untitled - By: dell - Thu Aug 15 2024
import sensor, image, time
from pyb import LED,Pin
from pyb import Timer
import lcd
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
#KEY1 = Pin('A0',Pin.OUT,Pin.PULL_UP)
#KEY2 = Pin('A2',Pin.OUT,Pin.PULL_UP)
#KEY3 = Pin('A5',Pin.OUT,Pin.PULL_UP)#A4A6 不行
#KEY4 = Pin('A7',Pin.OUT,Pin.PULL_UP)
#KEY5 = Pin('C4',Pin.IN,Pin.PULL_UP)
#KEY6 = Pin('B0',Pin.IN,Pin.PULL_UP)
#KEY7 = Pin('B2',Pin.IN,Pin.PULL_UP)
#KEY8 = Pin('E8',Pin.IN,Pin.PULL_UP)
KEY1 = Pin('E1',Pin.OUT,Pin.PULL_UP)
KEY2 = Pin('B9',Pin.OUT,Pin.PULL_UP)
KEY3 = Pin('B7',Pin.OUT,Pin.PULL_UP)#A4A6 不行
KEY4 = Pin('B5',Pin.OUT,Pin.PULL_UP)
KEY5 = Pin('B3',Pin.IN,Pin.PULL_UP)
KEY6 = Pin('D6',Pin.IN,Pin.PULL_UP)
KEY7 = Pin('D4',Pin.IN,Pin.PULL_UP)
KEY8 = Pin('D2',Pin.IN,Pin.PULL_UP)
def KEY44_Read():
KEY1.value(0)
KEY2.value(1)
KEY3.value(1)
KEY4.value(1)
if KEY5.value()==0:
return 10
elif KEY6.value()==0:
return 11
elif KEY7.value()==0:
return 12
elif KEY8.value()==0:
return 13
KEY1.value(1)
KEY2.value(0)
KEY3.value(1)
KEY4.value(1)
if KEY5.value()==0:
return 14
elif KEY6.value()==0:
return 15
elif KEY7.value()==0:
return 16
elif KEY8.value()==0:
return 17
KEY1.value(1)
KEY2.value(1)
KEY3.value(0)
KEY4.value(1)
if KEY5.value()==0:
return 18
elif KEY6.value()==0:
return 19
elif KEY7.value()==0:
return 20
elif KEY8.value()==0:
return 21
KEY1.value(1)
KEY2.value(1)
KEY3.value(1)
KEY4.value(0)
if KEY5.value()==0:
return 22
elif KEY6.value()==0:
return 23
elif KEY7.value()==0:
return 24
elif KEY8.value()==0:
return 25
return 0
KEY44_status =0
KEY44_val=0
def KEY44Proc():
global KEY44_status
KEY44_val = KEY44_Read()
# print("key1_read........")
if KEY44_val!=0 and KEY44_status!=0 :#2.按键被按下的瞬间,下降沿
# print("h01333333333333333333")
if KEY44_val==10:
print("keyval= 10")
elif KEY44_val==11:
print("keyval= 11")
elif KEY44_val==12:
print("keyval= 12")
elif KEY44_val==13:
print("keyval= 13")
elif KEY44_val==14:
print("keyval= 14")
elif KEY44_val==15:
print("keyval= 15")
elif KEY44_val==16:
print("keyval= 16")
elif KEY44_val==17:
print("keyval= 17")
elif KEY44_val==18:
print("keyval= 18")
elif KEY44_val==19:
print("keyval= 19")
elif KEY44_val==20:
print("keyval= 20")
elif KEY44_val==21:
print("keyval= 21")
elif KEY44_val==22:
print("keyval= 22")
elif KEY44_val==23:
print("keyval= 23")
elif KEY44_val==24:
print("keyval= 24")
elif KEY44_val==25:
print("keyval= 25")
if KEY44_val!=0 and KEY44_status==0 :#2.按键被按下的瞬间,按下不松手的状态
# print("h08888888888888888")
pass
KEY44_status=KEY44_val #获取最新状态
#----------定时器4中断函数
timer4cnt =0
def tick(timer): # we will receive the timer object when being called
global timer4cnt
timer4cnt+=1
# print("t400")
if timer4cnt==1:
timer4cnt =0
KEY44Proc()
#----------创建一个定时器
tim = Timer(4, freq=20) # create a timer object using timer 4 - trigger at 5Hz
tim.callback(tick) # set the callback to our tick function
#------------------------------
while(True):
clock.tick()
# img = sensor.snapshot()
# print(clock.fps())