树莓派制作激光报警器
$ 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》