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 :

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().

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

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

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


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

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
| Constant | Value | Description |
|---|---|---|
LED0 | 1 | Mask of LED 0. |
LED1 | 2 | Mask of LED 1. |
LED2 | 4 | Mask of LED 2. |
LED3 | 8 | Mask of LED 3. |
LED4 | 16 | Mask of LED 4. |
LED5 | 32 | Mask of LED 5. |
LEDALL | 63 | Mask of all the LEDs. |
led_on(mask, hexcolor)
Turn LEDs on with a fixed color.
| Parameter | Description |
|---|---|
mask | LEDs to use, combine LED0 to LED5 with |, or use LEDALL |
hexcolor | color as a "#RRGGBB" string |
led_off(mask)
Turn LEDs off.
| Parameter | Description |
|---|---|
mask | LEDs 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.
| Parameter | Description |
|---|---|
mask | LEDs to use, combine LED0 to LED5 with |, or use LEDALL |
period | pulse period in ms |
hexcolor | color as a "#RRGGBB" string |
led_blink(mask, period, hexcolor)
Make LEDs blink: they switch between the color and off.
| Parameter | Description |
|---|---|
mask | LEDs to use, combine LED0 to LED5 with |, or use LEDALL |
period | blink period in ms |
hexcolor | color as a "#RRGGBB" string |
led_transition(mask, duration, hexcolor)
Change the color of LEDs smoothly, from their current color to the new one.
| Parameter | Description |
|---|---|
mask | LEDs to use, combine LED0 to LED5 with |, or use LEDALL |
duration | duration of the transition in ms |
hexcolor | new 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.
| Parameter | Description |
|---|---|
mask | LEDs to use, combine LED0 to LED5 with |, or use LEDALL |
intensity | noise intensity of each component as a "#RRGGBB" string |
led_flicker_off(mask)
Stop the noise added with led_flicker().
| Parameter | Description |
|---|---|
mask | LEDs 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.
| Parameter | Description |
|---|---|
period | time between two shifts in ms |
direction | 0 to shift from left to right, 1 from right to left |
led_shifting_off()
Stop the shifting started with led_shifting().