Thursday, April 2, 2015

64. Another Python GUI to control the Pi 2B's GPIO Pins

An even quicker one here - just another script to create a Python GUI to control the GPIO ports.

The buttons are programmed so that when a particular button needs to be pressed for its respective colour to come on, it reads Turn (colour) On, and when the colour is on, the button reads Turn (colour) Off.

The configuration above has Red Off, Green ON and Blue ON, giving a beautiful cyan colour as in the picture below.

The Quit button is important - it closes the program down properly, so that all the GPIO ports are ready for the next program which may need to access them.  If we just closed the window without using the Quit button, the program would continue listening for button presses, even though the window had disappeared.  The Quit button, when pressed, invokes the Python function exit, which ensures a clean termination to the program.

The wiring part is exactly the same as the last post - 3 x 
330resistors, one between each of the red, green and blue RGB LED anodes and the Pi's GPIO ports 23, 24 and 25.  The Draft Guinness widget is still doing its job admirably!

Here is the code:
The original code was written by Matt Richardson at https://www.youtube.com/watch?v=xfxSH790rZ0  

Nice one Matt!

No comments:

Post a Comment