Leds¶
-
class
ev3dev2.led.Led(name_pattern='*', name_exact=False, desc=None, **kwargs)¶ Any device controlled by the generic LED driver. See https://www.kernel.org/doc/Documentation/leds/leds-class.txt for more details.
-
max_brightness¶ Returns the maximum allowable brightness value.
-
brightness¶ Sets the brightness level. Possible values are from 0 to
max_brightness.
-
triggers¶ Returns a list of available triggers.
-
trigger¶ Sets the LED trigger. A trigger is a kernel based source of LED events. Triggers can either be simple or complex. A simple trigger isn’t configurable and is designed to slot into existing subsystems with minimal additional code. Examples are the
ide-diskandnand-disktriggers.Complex triggers whilst available to all LEDs have LED specific parameters and work on a per LED basis. The
timertrigger is an example. Thetimertrigger will periodically change the LED brightness between 0 and the current brightness setting. Theonandofftime can be specified viadelay_{on,off}attributes in milliseconds. You can change the brightness value of a LED independently of the timer trigger. However, if you set the brightness value to 0 it will also disable thetimertrigger.
-
delay_on¶ The
timertrigger will periodically change the LED brightness between 0 and the current brightness setting. Theontime can be specified viadelay_onattribute in milliseconds.
-
delay_off¶ The
timertrigger will periodically change the LED brightness between 0 and the current brightness setting. Theofftime can be specified viadelay_offattribute in milliseconds.
-
brightness_pct¶ Returns LED brightness as a fraction of max_brightness
-
-
class
ev3dev2.led.Leds¶ -
set_color(group, color, pct=1)¶ Sets brightness of LEDs in the given group to the values specified in color tuple. When percentage is specified, brightness of each LED is reduced proportionally.
Example:
my_leds = Leds() my_leds.set_color('LEFT', 'AMBER')
With a custom color:
my_leds = Leds() my_leds.set_color('LEFT', (0.5, 0.3))
-
set(group, **kwargs)¶ Set attributes for each LED in group.
Example:
my_leds = Leds() my_leds.set_color('LEFT', brightness_pct=0.5, trigger='timer')
-
all_off()¶ Turn all LEDs off
-
reset()¶ Put all LEDs back to their default color
-
animate_stop()¶ Signal the current animation thread to exit and wait for it to exit
-
animate_police_lights(color1, color2, group1='LEFT', group2='RIGHT', sleeptime=0.5, duration=5, block=True)¶ Cycle the
group1andgroup2LEDs betweencolor1andcolor2to give the effect of police lights. Alternate thegroup1andgroup2LEDs everysleeptimeseconds.Animate for
durationseconds. Ifdurationis None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_police_lights('RED', 'GREEN', sleeptime=0.75, duration=10)
-
animate_flash(color, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration=5, block=True)¶ Turn all LEDs in
groupsoff/on tocoloreverysleeptimesecondsAnimate for
durationseconds. Ifdurationis None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_flash('AMBER', sleeptime=0.75, duration=10)
-
animate_cycle(colors, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration=5, block=True)¶ Cycle
groupsLEDs throughcolors. Do this in a loop where we display each color forsleeptimeseconds.Animate for
durationseconds. Ifdurationis None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_cyle(('RED', 'GREEN', 'AMBER'))
-
animate_rainbow(group1='LEFT', group2='RIGHT', increment_by=0.1, sleeptime=0.1, duration=5, block=True)¶ Gradually fade from one color to the next
Animate for
durationseconds. Ifdurationis None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_rainbow()
-
LED group and color names¶
EV3 platform
Led groups:
LEFTRIGHT
Colors:
BLACKREDGREENAMBERORANGEYELLOW
BrickPI platform
Led groups:
LED1LED2
Colors:
BLACKBLUE
BrickPI3 platform
Led groups:
LED
Colors:
BLACKBLUE
PiStorms platform
Led groups:
LEFTRIGHT
Colors:
BLACKREDGREENBLUEYELLOWCYANMAGENTA
EVB platform
None.