Pin output PWM

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 libraryControl pin mode
GPIO Zero LibraryDevice Class: LED (Output)
RPi.GPIO library/wirinPi libraryOutput 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 PWM output of the pin.

led.pulse can set the fade-in and fade-out time: in the code, it takes 3 seconds from off to on (fade in), and 1 second from on to off (fade out) (if no parameters are used, the default is 1 second).