Back in 2015, I had the idea for gpiozero — a Python library for Raspberry Pi, making programming GPIO devices simpler by abstraction: instead of thinking about pin channels, voltages, pull-up resistors and rising or falling edges, we think about buttons being pressed and released, sensors detecting light or motion, and motors driving forwards and backwards. gpiozero let you write code in these terms. We developed a device-focused API, and patterns emerged. We ended up supporting three types of programming: Procedural: while True: if button.is_pressed: led.on() else: led.off() Event-based: button.when_pressed = led.on button.when_released = led.off Declarative: led.source = button These three snippets achieve the same thing in different ways. One repeatedly asks the button if it is…
Gpiozero Flow
Advertisement