April 2017
Beginner to intermediate
312 pages
7h 23m
English
Let's review some uses of functions with the GPIO example. Functions can be used in order to handle specific events related to the GPIO pins of the Raspberry Pi. For example, the gpiozero library provides the capability of calling a function either when a button is pressed or released:
from gpiozero import Button def button_pressed(): print("button pressed")def button_released(): print("button released")#button is interfaced to GPIO 2 button = Button(2) button.when_pressed = button_pressed button.when_released = button_releasedwhile True: pass
In this example, we make use of the attributes when_pressed and when_released of the library's GPIO class. When the button is pressed, the function button_pressed is executed. ...
Read now
Unlock full access