OcchiMatrice
La classe EyesMatrix controlla la matrice LED NeoPixel (gli occhi di Eliobot): 2 matrici 8×8 per un totale di 128 LED.
Disposizione fisica
Œil droit (indices 0–63) Œil gauche (indices 64–127)
[ 0][ 1][ 2][ 3][ 4][ 5][ 6][ 7] [ 64][ 65][ 66][ 67][ 68][ 69][ 70][ 71]
[ 8][ 9][ 10][ 11][ 12][ 13][ 14][ 15] [ 72][ 73][ 74][ 75][ 76][ 77][ 78][ 79]
[ 16][ 17][ 18][ 19][ 20][ 21][ 22][ 23] [ 80][ 81][ 82][ 83][ 84][ 85][ 86][ 87]
[ 24][ 25][ 26][ 27][ 28][ 29][ 30][ 31] [ 88][ 89][ 90][ 91][ 92][ 93][ 94][ 95]
[ 32][ 33][ 34][ 35][ 36][ 37][ 38][ 39] [ 96][ 97][ 98][ 99][100][101][102][103]
[ 40][ 41][ 42][ 43][ 44][ 45][ 46][ 47] [104][105][106][107][108][109][110][111]
[ 48][ 49][ 50][ 51][ 52][ 53][ 54][ 55] [112][113][114][115][116][117][118][119]
[ 56][ 57][ 58][ 59][ 60][ 61][ 62][ 63] [120][121][122][123][124][125][126][127]
Inizializzazione
import board
from elio import EyesMatrix
eyes = EyesMatrix(board.IO2, brightness=0.05)
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
pin | Pin | — | Pin de la matrice NeoPixel |
brightness | float | 0.05 | Luminosité (0.0 à 1.0) |
Metodi di visualizzazione
set_matrix_colors(led_colors)
Definisce il colore di ciascun LED da un elenco di 128 tuple RGB.
colors = [(255, 0, 0)] * 64 + [(0, 0, 255)] * 64 # Œil droit rouge, gauche bleu
eyes.set_matrix_colors(colors)
clear_matrix()
Spegne tutti i LED.
eyes.clear_matrix()
set_matrix_logo(logo, color)
Visualizza un logo (elenco di 128 booleani) con un determinato colore.
eyes.set_matrix_logo(eyes.emotionHappy, (255, 200, 0))
Emozioni predefinite
La classe include loghi già pronti che raffigurano emozioni:
| Attribut | Description |
|---|---|
emotionHappy | Content |
emotionSad | Triste |
emotionAngry | En colère |
emotionNeutral | Neutre |
emotionThrilled | Enthousiaste |
emotionTired | Fatigué |
emotionAmazed | Étonné |
emotionDizzy | Étourdi |
emotionConfused | Confus |
emotionLove | Amour |
emotionKO | KO |
emotionMusic | Musique |
eyes.set_matrix_logo(eyes.emotionHappy, (255, 200, 0)) # Yeux jaunes contents
eyes.set_matrix_logo(eyes.emotionSad, (0, 100, 255)) # Yeux bleus tristes
Frecce predefinite
| Attribut | Description |
|---|---|
arrowRight | Flèche droite |
arrowLeft | Flèche gauche |
arrowUp | Flèche haut |
arrowDown | Flèche bas |
eyes.set_matrix_logo(eyes.arrowRight, (0, 255, 0))
Scorrimento del testo
scroll_matrix_text_both_eyes(text, color, speed=0.1)
Fa scorrere il testo su entrambi gli occhi da destra a sinistra.
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
text | str | — | Texte à afficher |
color | tuple | — | Couleur RGB |
speed | float | 0.1 | Délai entre chaque frame (secondes) |
eyes.scroll_matrix_text_both_eyes("Eliobot!", (255, 255, 0), speed=0.08)
scroll_matrix_text_eye(text, color, eye=0, speed=0.1)
Fa scorrere il testo su un occhio.
| Paramètre | Type | Défaut | Description |
|---|---|---|---|
text | str | — | Texte à afficher |
color | tuple | — | Couleur RGB |
eye | int ou str | 0 | 0 ou "right" = œil droit, 1 ou "left" = œil gauche |
speed | float | 0.1 | Délai entre chaque frame (secondes) |
eyes.scroll_matrix_text_eye("Hello", (0, 255, 0), eye="left", speed=0.1)
eyes.scroll_matrix_text_eye("42", (255, 0, 0), eye=0)
Caratteri supportati
Lo scorrimento supporta lettere (maiuscole e minuscole), numeri e simboli comuni: ? ! , . - _ / \ ( ) [ ] @ # $ = + * ^ & % | : ; ' < >
Esempio completo
import board
import time
from elio import EyesMatrix
eyes = EyesMatrix(board.IO2, brightness=0.05)
# Afficher une émotion
eyes.set_matrix_logo(eyes.emotionHappy, (255, 200, 0))
time.sleep(2)
# Faire défiler du texte
eyes.scroll_matrix_text_both_eyes("Bonjour!", (0, 200, 255), speed=0.08)
# Éteindre
eyes.clear_matrix()