注意,摄像头和这里的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())
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.