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-disk
andnand-disk
triggers.Complex triggers whilst available to all LEDs have LED specific parameters and work on a per LED basis. The
timer
trigger is an example. Thetimer
trigger will periodically change the LED brightness between 0 and the current brightness setting. Theon
andoff
time 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 thetimer
trigger.
-
delay_on
¶ The
timer
trigger will periodically change the LED brightness between 0 and the current brightness setting. Theon
time can be specified viadelay_on
attribute in milliseconds.
-
delay_off
¶ The
timer
trigger will periodically change the LED brightness between 0 and the current brightness setting. Theoff
time can be specified viadelay_off
attribute 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
group1
andgroup2
LEDs betweencolor1
andcolor2
to give the effect of police lights. Alternate thegroup1
andgroup2
LEDs everysleeptime
seconds.Animate for
duration
seconds. Ifduration
is 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
groups
off/on tocolor
everysleeptime
secondsAnimate for
duration
seconds. Ifduration
is 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
groups
LEDs throughcolors
. Do this in a loop where we display each color forsleeptime
seconds.Animate for
duration
seconds. Ifduration
is None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_cycle(('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
duration
seconds. Ifduration
is None animate for forever.Example:
from ev3dev2.led import Leds leds = Leds() leds.animate_rainbow()
-
LED group and color names¶
EV3 platform
Led groups:
LEFT
RIGHT
Colors:
BLACK
RED
GREEN
AMBER
ORANGE
YELLOW
BrickPI platform
Led groups:
LED1
LED2
Colors:
BLACK
BLUE
BrickPI3 platform
Led groups:
LED
Colors:
BLACK
BLUE
PiStorms platform
Led groups:
LEFT
RIGHT
Colors:
BLACK
RED
GREEN
BLUE
YELLOW
CYAN
MAGENTA
EVB platform
None.