Pulse Width Modulation (or PWM) is a technique for controlling power. We also use it here to control the brightness of each of the LEDs.

The diagram below shows the signal from one of the GPIO pins on the BBB.
Every 1/5000 of a second, the PWM output will produce a pulse from 3.3V down to 0V. The length of this pulse is controlled by the 'set_duty_cycle' function.

If the output is high for 90% of the time then the load will get 90% of the power delivered to it. We cannot see the LEDs turning on and off at that speed, so to us, it just looks like the brightness is different.
This guide was first published on Jul 09, 2013. It was last updated on Jul 09, 2013. This page (PWM) was last updated on May 19, 2019.