[Tutor] Python GPIO Code Help Needed
Alan Gauld
alan.gauld at btinternet.com
Sun Oct 26 14:41:13 CET 2014
On 26/10/14 01:05, Bill Bright wrote:
> The code polls the GPIO pins on a Raspberry Pi.
> When it detects a switch being flipped, it plays
> a corresponding audio file.
Does that mean in either direction? Or does it only play when the switch
goes ON?
(I'm not familiar with the Pi (although somebody recently
bought me one as a gift!) so don't know what these switches
look like - I'm guessing they are DIPs?)
> What I would like to do is when a switch is flipped have
> the audio play, then have the code pause until the switch
> is returned to normal (not repeating the audio),
> and then return to the while loop to poll for the next switch flip.
What happens if one of the other switches is flipped while you are
waiting? You need to think through all the possible combinations
that could happen at any one time and the resultant actions. (In
professional coding this would usually involve a "state machine")
So the questions I have:
1) If I flip a switch a tune plays.
- What if I flip another switch while the first is playing?
- What if I flip another switch after the tune finishes?
- What if I restore the switch?
- do I play it again? Do I play a different tune? or None?
2) What if I flip multiple switches together?
- Do all the related tunes play? or none?
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list