[Tutor] Python GPIO Code Help Needed
Bill Bright
wcb_rlb at bellsouth.net
Sun Oct 26 23:37:37 CET 2014
Thanks to everyone for the help. The code below seems to work. My question is why does oldstates need to multiplied by 32? Does this mean that the code will only work for 32 switches before I have to reset the Pi?
Code:
#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
oldstates=[True]*32
def changed(channel):
newstate = GPIO.input(channel)
change = oldstates[channel] and not newstate
oldstates[channel] = newstate
return change
while True:
if changed(23):
os.system('mpg321 -g 95 a.mp3')
if changed(24):
os.system('mpg321 -g 95 b.mp3')
if changed(25):
os.system('mpg321 -g 95 c.mp3')
sleep(1.1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141026/dacb6046/attachment-0001.html>
More information about the Tutor
mailing list