樹梅派-ブザー鳴動スクリプトの制御(python)
719 ワード
import RPi.GPIO as GPIO
from gpiozero import Buzzer
import time
def init():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN)
GPIO.setup(25,GPIO.OUT)
pass
def beep():
#beep(on_time=1,off_time=1,n=None,background=Ture)
bz=Buzzer(25)
bz.beep(0.1,0.1,1,False)
#GPIO.output(25,GPIO.HIGH)
#time.sleep(.3)
#GPIO.output(25,GPIO.LOW)
def detct():
for i in range(1,101):
#while True:
if GPIO.input(17)==True:
print "ok"
beep()
time.sleep(2.5)
else:
print("no")
time.sleep(2)
time.sleep(1)
init()
beep()
detct()
GPIO.cleanup()