PyGlow is a small Python module for the PiGlow addon by Pimoroni which will let you flex the LED muscles of this fantastic addon. It was started as PiGlow by Jason (@Boeeerb) but I (@ben_leb) decided to fork it to provide a more clean and easier to use module.
- Control a single LED, a single arm, a single color or any combination of these
- Pulsing LED
- Gamma Correction (makes the progression from
0-255
more visually linear)
For instructions on how to setup Raspberry Pi for use with PyGlow, please see https://github.com/pimoroni/piglow#setting-up-your-raspberry-pi
PyGlow module requires the smbus
Python module. It must be installed before
the PyGlow module is used. Example of installation for
RASPBIAN:
sudo apt-get install python-smbus
Now create a directory for python modules and then change to that directory:
$ mkdir -p ~/lib/python/
$ cd ~/lib/python/
Next get the latest version of PyGlow python module:
git clone https://github.com/benleb/PyGlow.git
This will download the PyGlow module into the ~/lib/python/PyGlow
directory.
In order to make the PyGlow module accessible for other scripts, a system
environment variable with a path to the module must be exported (you can add
it into your ~/.bashrc
):
export PYTHONPATH=$PYTHONPATH:~/lib/python
Now go to the examples
directory and run the testing script:
cd ~/lib/python/PyGlow/examples/
python test.py
If the script loads, you can set the brightness of each LED color group by
typing a number between 0
(off) and 255
(brightest).
See the other files in the examples
directory for more examples
of how to use PyGlow.
If you just want to install the PyGlow library for use in your own project, you can also install it using pip
$ pip install git+https://github.com/benleb/PyGlow.git
The PyGlow.py files will be downloaded and placed in the site-packages directory ready for use.
In order to be able to use PyGlow module, the PyGlow()
class must be
imported:
from PyGlow import PyGlow
Then it's possible to instantiate the PyGlow()
object:
pyglow = PyGlow()
The PyGlow()
object can accept four optional parameters:
brightness=None
- sets default brightness level (value: number from0
and255
)speed=None
- sets default pulsing speed in milliseconds (value: number > 0)pulse=None
- enables pulsing by default (value:True
orFalse
)pulse_dir=None
- sets default pulsation direction (value:UP
,DOWN
,BOTH
)
The default parameter values are used across all functions unless overridden on
the function level. If the default parameter value is not set during the object
instantiation, it must be set on the function level. The value for the parameter
speed
and pulse_dir
must be set only if the parameter pulse=True
.
Functions provided by the PyGlow()
object are:
Sets the specific led
to the brightness
level. The led
is in the range of
1
to 18
. The led
parameter can also be a list of individual leds. The
other parameters can have the same value like in the case of the object
instantiation.
Sets the specific color
group to the brightness
level. The color
group
can be either a number or a name:
1
=white
2
=blue
3
=green
4
=yellow
5
=orange
6
=red
The other parameters can have the same value like in the case of the object instantiation.
Sets the specific LED arm
to the brightness
level. The arm
value can be
either 1
, 2
or 3
. The other parameters can have the same value like in
the case of the object instantiation.
Sets all LEDs to the brightness
level. The parameters can have the same value
like in the case of the object instantiation.
Prepares the list of leds
to be set to the brightness
level. The leds
list can be composed of numbers from 1
to 18
or connection of color
name
and arm
number (e.g. red1
will light up the red
LED in the arm 1
). The
other parameters can have the same value like in the case of the object
instantiation. The set brightness
will take effect only after the
update_leds()
is called (see bellow).
Sets the brightness level of all LEDs specified by the set_leds()
function.
leds_odd = [1, 3, 5, 7, 9, 11, 13, 15, 17]
leds_even = [2, 4, 6, 8, 10, 12, 14, 16, 18]
pyglow.set_leds(leds_odd, 150)
pyglow.set_leds(leds_even, 10)
pyglow.update_leds()
pyglow.py
- Python module providing the PyGlow classexamples/bin_clock.py
- binary clock by Jiri Tyrexamples/clock.py
- binary clock by Jason (@Boeeerb)examples/cpu.py
- CPU percentage indicator by Jason (@Boeeerb)examples/pulsetest.py
- shows how to use LED pulsingexamples/set_leds.py
- shows howset_leds()
andupdate_leds()
worksexamples/test.py
- allows to choose the brightness of each LED color group
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This module is release under the MIT license.