On 06/18/2015 01:35 PM, Oscar Benjamin wrote:
> I use the following. I found in testing that when you push the button it
> prints 'Button pressed' 10 times a second (in actual use it calls poweroff
> so I guess bounce isn't an issue there). Is there some reason it needs to
> be cleverer in this case?
Yes, that would be expected, given your code has a while loop that never
exits. Just curious what you expect the code to do that it's not doing.
You are probably right that debouncing isn't important in your
application. So just add your poweroff command after the print()
statement, and break out of the loop:
if not GPIO.input(PIN_NUM):
# run shutdown command here
it seems you don't understand event based programming. root.mainloop()
never exits. It waits for the user input and does the dispatching, i.e.
when a key is pressed, then according to your bindings, the functions
red1, yellow1, blue1 are called, which set a variable but do not do
nything else. To see that, just insert a print statement into these
Now your job is to also do the functionality there, i.e. you have to
reformulate your task (waiting for red, then blue...) as a state
machine. Alternatively you can circumvent to redo the logic in a state
machine by using a coroutine.
You should read a text about GUI programming, or more specifically event
based programming, to understand your mistake.
Christian, are you suggesting I learn to do everything perfectly before
I ask how to do everything perfectly?
Despite your tone and insults I honestly appreciate the response. I know
what to focus on and less than 5 minutes from now I will be looking for e-
books on the specific subjects you point me to and will have a better
idea of where the issues are.
On 06/20/2015 09:02 AM, John McKenzie wrote:
> Guys, thanks for the various code examples for GPIO and the warning
> about debouncing issues. I am still considering going the route of more
> complex wiring and doing it a more traditional GPIO way.
You can wire up the button without a little breadboard or circuit board
using this general diagram:
Just solder the resistors to the wires themselves, and keep them close
to the pi to keep them clean. Then you you just have to route one wire
per switch, with one common wire hitting the other side of each switch.
Probably you will want to use the pull-up version where the switch
pulls the signal down to ground. You may want to use a header to plug
into the rpi. But besides that should just be a matter of routing wires.
But on the original track, you might want to ask on the kade forums if
there's any way to interact with kade and get events besides HID
emulation. For example, maybe you could communicate with it over a
virtual serial port. Or some other protocol so you don't have to worry
about ttys and Linux kernel HID handling for your program, especially in
a headless environment. Using HID emulation makes sense in a MAME
arcade environment but not for a headless raspberry pi application.