try:
while True:
status = GPIO.input(uPin)
if status == 1: ##高电平说明有振动
print '路面不平'
elif status == 0:
print '==='
time.sleep(0.3) ##检测频率 可调节
except KeyboardInterrupt:
pass
n = 1
moment = int(raw_input('老狼 老狼几点了:')) ##接收问询输入
if moment > 12: moment = 12 ##12点老狼就要来了
try:
while True:
if n > moment: break
print n
GPIO.output(soundPin, GPIO.LOW) ##输出低电平 然后传感器发出声音
time.sleep(0.15) ##声音输出时间
GPIO.output(soundPin, GPIO.HIGH) ##输出高电平 然后声音输出终止
time.sleep(0.15) ##声音中断时间
n += 1