import sensor, image, time
from pyb import LED,Pin
from pyb import Timer
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing(320,320)
sensor.set_auto_whitebal(False)
#gain_par =0.8
#sensor.set_auto_gain(False, gain_db_ceiling=gain_par) # Default gain 10.
sensor.set_auto_gain(False) # Default gain 10.
EXPOSURE_MICROSECONDS = 100000
#sensor.set_auto_exposure(False, exposure_us=EXPOSURE_MICROSECONDS)
sensor.set_auto_exposure(True, exposure_us=EXPOSURE_MICROSECONDS)
try:
# The camera will now focus on whatever is in front of it.
sensor.ioctl(sensor.IOCTL_TRIGGER_AUTO_FOCUS)
except:
raise (Exception("Auto focus is not supported by your sensor/board combination."))
sensor.skip_frames(time = 200)
clock = time.clock()
#blue_led = LED(1)
KEY = Pin('C13',Pin.IN,Pin.PULL_DOWN)
KEY1 = Pin('A0',Pin.IN,Pin.PULL_UP)
KEY2 = Pin('A2',Pin.IN,Pin.PULL_UP)
KEY3 = Pin('A5',Pin.IN,Pin.PULL_UP)#A4A6 不行
KEY4 = Pin('A7',Pin.IN,Pin.PULL_UP)
KEY5 = Pin('C4',Pin.IN,Pin.PULL_UP)
KEY6 = Pin('B0',Pin.IN,Pin.PULL_UP)
print("You're on camera!")
keycount=0
# 轻触开关
waitkeyflag=0
keyval=0
#等开关按下并松开
def wait_key():
global keyval,waitkeyflag
while KEY.value():
while KEY.value():
while KEY.value(): #wait key up
i=0 #anything you like
print("here01")
keyval=100
waitkeyflag=1
key1_status=0
key2_status=0
key3_status=0
key4_status=0
key5_status=0
key6_status=0
key_val =0
key_testnum=0;
def KEY1_Read():
global key1_status
global waitkeyflag
# print("key1_read........")
if KEY1.value()==0 and key1_status==1 :#2.按键被按下的瞬间,下降沿
waitkeyflag =1
print("h01333333333333333333")
elif KEY1.value()==0 and key1_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("u01444444444444444444")
key1_status=KEY1.value() #获取最新状态
def KEY2_Read():
global key2_status
global waitkeyflag
if KEY2.value()==0 and key2_status==1 :#2.按键被按下的瞬间,下降沿
#用户自定义函数
waitkeyflag=0
print("key2 is up to down")
elif KEY2.value()==0 and key2_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("key2 is downing")
key2_status=KEY2.value() #获取最新状态
def KEY3_Read():
global key3_status
global waitkeyflag
if KEY3.value()==0 and key3_status==1 :#2.按键被按下的瞬间,下降沿
#用户自定义函数
print("key3 is up to down")
elif KEY3.value()==0 and key3_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("key3 is downing")
key3_status=KEY3.value() #获取最新状态
def KEY4_Read():
global key4_status
global waitkeyflag
if KEY4.value()==0 and key4_status==1 :#2.按键被按下的瞬间,下降沿
#用户自定义函数
print("key4 is up to down")
elif KEY4.value()==0 and key4_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("key4 is downing")
key4_status=KEY4.value() #获取最新状态
def KEY5_Read():
global key5_status
global waitkeyflag
if KEY5.value()==0 and key5_status==1 :#2.按键被按下的瞬间,下降沿
#用户自定义函数
print("key5 is up to down")
elif KEY5.value()==0 and key5_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("key5 is downing")
key5_status=KEY5.value() #获取最新状态
def KEY6_Read():
global key6_status
global waitkeyflag
if KEY6.value()==0 and key6_status==1 :#2.按键被按下的瞬间,下降沿
#用户自定义函数
print("key6 is up to down")
elif KEY6.value()==0 and key6_status==0 :#3.按键被按下的状态,
#用户自定义函数
print("key6 is downing")
key6_status=KEY6.value() #获取最新状态
#定时器中断,回调函数
timer4cnt =0
def tick(timer): # we will receive the timer object when being called
global timer4cnt
timer4cnt+=1
# print("t400")
if timer4cnt==2:
timer4cnt =0
KEY1_Read()
KEY2_Read()
KEY3_Read()
KEY4_Read()
KEY5_Read()
KEY6_Read()
# print("t9")
# KEY2_Read()
# KEY3_Read()
# KEY4_Read()
# KEY5_Read()
# KEY6_Read()
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()
if waitkeyflag==0:
wait_key()
# print(waitkeyflag)
# print("wait key00")
elif waitkeyflag==1 :
img = sensor.snapshot()
print(clock.fps())