Welcome to Raspberry Pi 5 repository
5.Pin output high and low levels
Pin output high and low levels
For controlling the Raspberry Pi GPIO pins, our tutorial uses the GPIO Zero library.
1. Driver library
If users have used the RPi.GPIO library and wirinPi library before, they will find that the GPIO Zero library and the RPi.GPIO library/wirinPi library handle pins differently:
| Driver library | Control pin mode |
|---|---|
| GPIO Zero Library | Device Class: LED (Output) |
| RPi.GPIO library/wirinPi library | Output status |
The GPIO Zero library has more control methods associated with the device, while the RPi.GPIO library and wirinPi library control pins directly.
2. LED
In the GPIO Zero library, we can use the LED interface to control the output high and low levels of the pins.
Control BCM pin number 17 high and low levels: high and low level output interval 1s
xfrom gpiozero import LEDfrom time import sleepled = LED(17)while True:led.on()sleep(1)led.off()sleep(1)
Control BCM pin number 17 high and low levels: high and low level output interval 1s (reversed)
xxxxxxxxxxfrom gpiozero import LEDfrom time import sleepled = LED(17)while True:led.toggle()sleep(1)
Note: If you connect an LED light to the Raspberry Pi, be sure to connect a resistor in series.