From the course: Raspberry Pi: GPIO

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Python and RPi.GPIO control of GPIO

Python and RPi.GPIO control of GPIO

From the course: Raspberry Pi: GPIO

Start my 1-month free trial

Python and RPi.GPIO control of GPIO

- [Instructor] RPi.GPIO is a code library that allows Python to communicate with the GPIO. It's been around since January of 2012 and is widely used and supported. In fact, GPIO zero is based on RPi.GPIO. So let's take a look at how to implement code to control our binary counter circuit. In lines four through 13 is basic set up, we import some libraries and create a few variables. Note line 11, RPi.GPIO doesn't have an LED board construct like GPIO zero. Instead, LEDs can be stored as a Python tuple. RPi.GPIO can handle interrupts and the functions defined in lines 16 through 27 handle these interrupts. The first, on line 16, handled reset, loops while the button returns zero. The button we have set up, returns zero if it's pressed and one if it's released. The not in line 17 inverts the zero, so that the button value reflects the intended logic. While the button is pressed, line 18 sets all of the LEDs to high,…

Contents