Aller au contenu principal

LEDs

OLEM possède 6 LEDs RVB, une à chaque sommet. Elles peuvent servir à éclairer les zones sous OLEM. Leur numéro est indiqué sur l'image ci-dessous :

Numéro de chaque LED

Chaque LED peut être contrôlée individuellement. La plupart des fonctions utilisent des masques pour choisir les LEDs. Les masques font 6 bits, un par LED, le bit n correspondant à la LED n. Ainsi, un masque égal à 0x01 sélectionne la LED 0, tandis qu'un masque égal à 0x1A sélectionne les LEDs 5, 4 et 2. Le module fournit des constantes pour chaque LED et pour toutes les LEDs à la fois.

Les couleurs sont données sous forme de chaînes hexadécimales au format "#RRGGBB", avec noir = "#000000" et blanc = "#FFFFFF".

Plusieurs effets peuvent être appliqués aux LEDs :

Le clignotement alterne entre 2 couleurs, voir led_blink().

Effet de clignotement

La transition change progressivement la couleur des LEDs, voir led_transition().

Effet de transition

La pulsation alterne progressivement entre 2 couleurs, voir led_pulse().

Effet de pulsation

Le scintillement ajoute du bruit à une couleur, voir led_flicker().

Scintillement faible

Scintillement fort

Le décalage transfère la configuration de chaque LED à sa voisine, voir led_shifting().

Effet de décalage

Exemples​

Masques​

Chaque LED est allumée seule, puis deux à la fois.

import olem

print("Begin leds mask test")
print("Turn on each led for 1000 ms")
mask = 1
for i in range(6):
print(mask)
olem.led_on(mask, "#FFFFFF")
olem.delay_ms(1000)
olem.led_off(olem.LEDALL)
mask = mask * 2

print("2 leds at once")
olem.led_on(olem.LED1 | olem.LED3, "#FFFFFF")
olem.delay_ms(1000)
olem.led_on(olem.LED0 | olem.LED5, "#FFFFFF")
olem.delay_ms(1000)
olem.led_on(olem.LED2 | olem.LED4, "#FFFFFF")
olem.delay_ms(1000)

print("End leds mask test")

Effets​

Chaque effet est montré 3 fois, de plus en plus lentement.

import olem

print("Testing visual effects")

time_step = 1000
for i in range(3):
period = time_step * (i + 1)

print("\ton")
olem.led_on(olem.LEDALL, "#0000FF")
olem.delay_ms(period * 3)

print("\toff")
olem.led_off(olem.LEDALL)
olem.delay_ms(period * 3)

print("\ttransition")
olem.led_transition(olem.LEDALL, period, "#FFFF00")
olem.delay_ms(period * 3)

print("\tpulse")
olem.led_pulse(olem.LEDALL, period, "#00FFFF")
olem.delay_ms(period * 3)

print("\tblink")
olem.led_blink(olem.LEDALL, period, "#FF00FF")
olem.delay_ms(period * 3)

print("End of led testing")

Décalage et scintillement​

import olem

# Deux LEDs de couleurs différentes tournent autour d'OLEM
olem.led_off(olem.LEDALL)
olem.led_on(olem.LED0, "#FF0000")
olem.led_on(olem.LED3, "#0000FF")
olem.led_shifting(200, 0)
olem.delay_ms(5000)
olem.led_shifting_off()

# Une pulsation avec du bruit par-dessus, comme une flamme
olem.led_pulse(olem.LEDALL, 2000, "#FF6000")
olem.led_flicker(olem.LEDALL, "#402000")
olem.delay_ms(5000)
olem.led_flicker_off(olem.LEDALL)
olem.led_off(olem.LEDALL)

Constantes et fonctions​

Constants​

ConstantValueDescription
LED01Mask of LED 0.
LED12Mask of LED 1.
LED24Mask of LED 2.
LED38Mask of LED 3.
LED416Mask of LED 4.
LED532Mask of LED 5.
LEDALL63Mask of all the LEDs.

led_on(mask, hexcolor)​

Turn LEDs on with a fixed color.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
hexcolorcolor as a "#RRGGBB" string

led_off(mask)​

Turn LEDs off.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL

led_pulse(mask, period, hexcolor)​

Make LEDs pulse: they fade smoothly in and out of the color.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
periodpulse period in ms
hexcolorcolor as a "#RRGGBB" string

Make LEDs blink: they switch between the color and off.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
periodblink period in ms
hexcolorcolor as a "#RRGGBB" string

led_transition(mask, duration, hexcolor)​

Change the color of LEDs smoothly, from their current color to the new one.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
durationduration of the transition in ms
hexcolornew color as a "#RRGGBB" string

led_flicker(mask, intensity)​

Add random noise to the color of LEDs, on top of their current effect: it can be used while LEDs are pulsing for example.

At each refresh, a random value of up to +/- half of the intensity is added to each color component. For example led_flicker(LEDALL, "#100020") adds up to +/- 8 to the red and up to +/- 16 to the blue of all the LEDs.

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL
intensitynoise intensity of each component as a "#RRGGBB" string

led_flicker_off(mask)​

Stop the noise added with led_flicker().

ParameterDescription
maskLEDs to use, combine LED0 to LED5 with |, or use LEDALL

led_shifting(period, direction)​

Periodically move the configuration of each LED to its neighbour, so that the LED pattern turns around OLEM.

ParameterDescription
periodtime between two shifts in ms
direction0 to shift from left to right, 1 from right to left

led_shifting_off()​

Stop the shifting started with led_shifting().