树莓派制作激光报警器

 

$ sudo pip install RPi.GPIO

 

import RPi.GPIO as GPIO, time, os

GPIO.setmode(GPIO.BOARD)

def RCtime(RCpin):
        reading = 0
        GPIO.setup(RCpin, GPIO.OUT)
        time.sleep(0.1)
        GPIO.setup(RCpin, GPIO.IN)
        while(GPIO.input(RCpin) == GPIO.LOW):
                reading += 1
        return reading

while 1:
        print RCtime(22)
        while (RCtime(22) > 50):
                print "ALARM!"
                alarm = "aplay ALARM9.WAV"
                os.system(alarm)

 

 

参考文章:

《Configuring ALSA Audio output on Analog and HDMI of Raspberry Pi》

《A Raspberry Pi Laser-tripwire》

《5.2. Working with Sound - Playing a sound with Python》

《Reading a Photocell with a Raspberry Pi》

posted @ 2016-08-21 21:50  Hardi  阅读(649)  评论(0编辑  收藏  举报