1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import RPi.GPIO as GPIO import time PIN_NO = 10 #GPIO编号,可自定义 GPIO.setmode(GPIO.BOARD) GPIO.setup(PIN_NO, GPIO.OUT) #哔1次,时长作为参数传递 def beep(seconds): GPIO.output(PIN_NO, GPIO.HIGH) time.sleep(seconds) GPIO.output(PIN_NO, GPIO.LOW) #哔N次,时长、间隔时长、重复次数作为参数传递 def beepAction(secs, sleepsecs, times): for i in range(times): beep(secs) time.sleep(sleepsecs) #beepAction(0.02,0.02,30) |
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 | import RPi.GPIO as GPIO import time import libbeep while True: t = time.localtime() h = t.tm_hour m = t.tm_min s = t.tm_sec w = time.strftime('%w',t) print h,m,s,w time.sleep(0.3) if m == 0 and s == 0: if h>22 or h<8:#为了晚上22点之后,上午8点之前不被打扰,设定了条件 print "continued" continue if h>12: h = h-12 libbeep.beepAction (0.3,0.5,h) time.sleep(1) if m == 30 and s == 0: if h>22 or h<8: print "continued" continue libbeep.beepAction (0.05,0.05,2) time.sleep(1) |
1 | sudo python alarm.py |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |