this is a beginners question, I suppose. How can I write a python code that allows the use of 2 (or more) push buttons connected to the GPIO? Each button should start a different shell script. The buttons are connected to the 3.3V pin and through a resistor to a GPIO pin. Also, I think, de-bouncing is necessary for the plan. All the simple tutorials deal only with one button and the more complex projects have a lot of code I don't understand. I tried a bit of copy/pasting, but without success. Help would be appreciated. Bye SG
Almost sounds like a homework issue :-) As such (and that this is not really a programming site) I would break the problem down as follows:
- Understand how to import the GPIO Zero, time and subprocess modules into your program
- Understand how to use the sys module to call to trigger the shell scripts AND report their return codes (assuming they do)
- Understand how to use the basic button function of GPIO Zero using the wait option. Test pull up / down, wait and bounce options. Check both switches work the way you want by testing each in its own program
- Create a basic loop in Python that waits till you press ctrl-c and end without an error message
- Change the loop with
sleepso other things can run
- Change one of the
buttonfunctions to use the callback capability to action the call to the script
- Change the final
buttonfunction to use the callback to run the other script
Try not to use copy and paste (though I guess we all do) - it never teaches you the basics of coding or how to solve problems...
Done - voted close as the issue was way too wide ranging.