$ 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》
时间: 2024-10-28 11:46:27