From the GPIO header of a machine like the Raspberry PI, the pins are on or off, and nothing in between.
This is why it is called digital: 0 or 1.
The pending question here is "How can I send an analog signal?".
It could be used for example to make a led glow, up or down, to display a light, with an intensity proportinal to some quantity to render.
In the case of an led - or any light source - PWM + POV is a possible solution.
PWM stands for Pulse Width Modulation, and POV stands for Persistence of Vision.
The persistence of vision is this characteristic of the human retina, not being able to discern images that appear for less than one 10th of a second. This allows us for example to watch a movie, without seeing each frame, but instead, having an impression of a movement. In a movie, there are in general 24 frames per second.
Along the same lines, this means that if a led is blinking faster than 10 times per second, most people will not see it blinking, but rather glowing.
This is where we talk about making the led blink...
The time during which the led is on is called the pulse.
For example, if we have a cycle of 100 ms, if the pulse is 50 ms long, the led will be seen as if is was glowing at 50% of its full power.
The code is not rocket science, but quite interesting though, as each pin has to be managed in its own thread, as the same Java class might need to manage several such pins simultaneously. The class to use is
raspisamples.pwm.PWMPin. This one extends
raspisamples.pwm.GPIOPinAdapter, which itself implements the
Here is the example
raspisamples.Real4PWMLed at work, launch it from the script named
In the clip above: