piripherals.led module¶
Things that have to do with controlling LEDs
-
class
piripherals.led.
NeoPixels
(*args, **kwargs)[source]¶ Bases:
object
an interface to NeoPixel LEDs based on rpi_ws281x.
This wraps around PixelStrip and adds additional functionality, especially asynchronous animation support.
Constructor arguments are passed to PixelStrip.
Parameters: - num (int) – # of LEDs on the strip
- pin (int) – BCM pin number of data pin. not all pins are allowed, see pin usage information of rpi_ws281x.
-
animate
(func, atexit=None, freq=1, period=0, timeout=0, cycles=0, fade=0, delay=0.01, wait=False)[source]¶ asynchronous animation
The animation is executed on a separate thread. The animation is stopped, when any function, that changes the state of the LEDs, is called. The animation is defined in
func
. This function gets passed 3 arguments:p
- raw PixelStrip, call methods of this to manipulate the LEDs,- which results in the animation
s
- normalized time in [0,1] in animation period, use this- to create cyclic animations
t
- time in seconds since startof animation
func
is called repeatedly withdelay
between the calls.Parameters: - func (callable(p,s,t)) – animation function
- atexit (callable()) – exit hook, function to call after animation
- freq (float) – animation frequency in Hz
- period (float) – animation period in seconds (freq=1/period), give either freq or period, period has higher priority
- timeout (float) – animation duration in seconds
- cycles (float) – animation cycle count, (timeout=cycles/freq) give either timeout or cycles, cycles has higher priority
- fade (float) – fade out animation over this number of seconds (sets timeout=fade)
- delay (float) – delay in seconds between calls of func
- wait (bool) – wait for animation to finish, synchronous animation, requires timeout
-
blink
(pattern='10', fade=0, color=None, **kwargs)[source]¶ blink LEDs on strip with given blink pattern.
Parameters: - pattern (str) – the blink pattern, that is played back in each
- period. It is either a str of 1 and 0 without space, (animation) –
- a str with space separated float brightness values. (or) –
for other args see
animate()
-
breathe
(n=1, fade=0, color=None, **kwargs)[source]¶ brightness breathing animation.
This was inspired by http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/.
Parameters: - n (float) – nonlinearity of brightness function
- color (tuple(r,g,b)) – color set on animation start
for other args see
animate()
-
brightness
(b=1)[source]¶ set brightness, affects all LEDs
Parameters: b (float) – brightness in range [0,1]
-
clock
(secs=1, **kwargs)[source]¶ a clock.
Works best on a circular strip with 12 LEDs. Hours are red, minutes are green, seconds are blue.
Parameters: secs (int) – show blue seconds 0 = do not show seconds, 1 = show blue seconds, 2 = flash white seconds in 12th position, 3 = run white seconds around in loop for other args see
animate()
-
color
(led=None, r=0, g=-1, b=-1, v=-1)[source]¶ set color
Parameters: - led (int) – # of LED on strip to set the color for, None = all LEDs
- r (float) – red value from range [0,1], if not given r = 0
- g (float) – green value from range [0,1], if not given g = r
- b (float) – blue value from range [0,1], if not given b = g
- v (float) – brightness, see
brightness()
, is applied to all LEDs