Ligne 3 : |
Ligne 3 : |
| | | |
| Ce tutoriel couvre plusieurs modèles de cartes sous MicroPython: | | Ce tutoriel couvre plusieurs modèles de cartes sous MicroPython: |
− | * {{pl|846|Feather ESP8266}} + {{pl|879|OLED FeatherWing}} | + | * {{pl|846|Feather ESP8266}} + {{pl|879|OLED FeatherWing}} <br />[[Fichier:FEATHER-MICROPYTHON-OLED-10a.png|120px]] |
| | | |
| == Installer la bibliothèque == | | == Installer la bibliothèque == |
Ligne 41 : |
Ligne 41 : |
| == Brancher == | | == Brancher == |
| === OLED Featherwing === | | === OLED Featherwing === |
− | Le FeatherWing OLED s'insère simplement sur la carte Feather (ex: Feather ESP8266) et propose une résolution de 128 x 32 pixels. | + | Le {{pl|879|FeatherWing OLED}} s'insère simplement sur la carte Feather (ex: Feather ESP8266) et propose une résolution de 128 x 32 pixels. |
| | | |
| [[Fichier:FEATHER-MICROPYTHON-OLED-10a.png|200px]] [[Fichier:FEATHER-MICROPYTHON-OLED-10b.png]] | | [[Fichier:FEATHER-MICROPYTHON-OLED-10a.png|200px]] [[Fichier:FEATHER-MICROPYTHON-OLED-10b.png]] |
Ligne 76 : |
Ligne 76 : |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | === Tester lcd === | + | === Tester la bibliothèque === |
| Dans les exemples ci-dessous, voici les paramètres que vous retrouverez dans les différents appels de fonction: | | Dans les exemples ci-dessous, voici les paramètres que vous retrouverez dans les différents appels de fonction: |
| | | |
Ligne 115 : |
Ligne 115 : |
| # color = pixel( x, y ) | | # color = pixel( x, y ) |
| # Retourne 1 si le point est allumé, sinon 0. | | # Retourne 1 si le point est allumé, sinon 0. |
− | c = lcd.rect( 3, 4 ) | + | c = lcd.pixel( 3, 4 ) |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
Ligne 213 : |
Ligne 213 : |
| Il est assez facile de créer et afficher une icône. | | Il est assez facile de créer et afficher une icône. |
| | | |
− | La fonction `draw_icon()`. | + | L'icône est définie avec un 1 pour un point allumé et un 0 pour un point éteint: |
| + | |
| + | <syntaxhighlight lang="python">HEART_ICON = [ |
| + | [0,0,0,0,0,0,0,0,0,0,0], |
| + | [0,0,1,1,1,0,1,1,1,0,0], |
| + | [0,1,1,0,1,1,1,1,1,1,0], |
| + | [0,1,0,1,1,1,1,1,1,1,0], |
| + | [0,1,1,1,1,1,1,1,1,1,0], |
| + | [0,0,1,1,1,1,1,1,1,0,0], |
| + | [0,0,0,1,1,1,1,1,0,0,0], |
| + | [0,0,0,0,1,1,1,0,0,0,0], |
| + | [0,0,0,0,0,1,0,0,0,0,0], |
| + | [0,0,0,0,0,0,0,0,0,0,0] ]</syntaxhighlight> |
| + | |
| + | La fonction {{fname|draw_icon()}} permet de dupliquer le contenu d'un "pseudo tableau" (l'icône) sur l'écran aux coordonnées x,y. |
| | | |
| <syntaxhighlight lang="python">def draw_icon( lcd, from_x, from_y, icon ): | | <syntaxhighlight lang="python">def draw_icon( lcd, from_x, from_y, icon ): |
Ligne 222 : |
Ligne 236 : |
| lcd.pixel( from_x+x, | | lcd.pixel( from_x+x, |
| from_y+y, | | from_y+y, |
− | color ) | + | color )</syntaxhighlight> |
− | </syntaxhighlight> | + | |
| + | Le code est prévu pour définir des icônes avec un Canal Alpha (avec des 1, 0 et None). |
| + | * Les points marqués 1 sont allumés. |
| + | * Les points marqués 0 sont éteints. |
| + | * Les points marqués None sont ignorés (donc non modifiés sur l'affichage). |
| + | |
| + | Dans l'exemple ci-dessous, la variable {{fname|a}} est assignée a {{fname|None}} et utilisé comme valeur de Canal Alpha. |
| + | |
| + | <syntaxhighlight lang="python">a = None |
| + | FB_ICON = [ |
| + | [a,a,a,a,a,a,a,a,a,a,0,0,a,a,a,a,a], |
| + | [a,a,a,a,a,a,a,a,a,0,0,0,0,a,a,a,a], |
| + | [a,a,a,a,a,a,a,a,0,0,1,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,a,0,0,1,0,1,0,0,a,a,a], |
| + | [a,a,a,a,a,a,0,0,1,0,0,1,0,0,0,0,a], |
| + | [0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0], |
| + | [0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0], |
| + | [0,0,1,1,1,1,0,a,0,1,1,1,1,1,0,0,a], |
| + | [a,0,0,0,0,0,0,a,0,0,0,0,0,0,0,a,a], |
| + | [a,0,0,0,0,0,a,a,a,0,0,0,0,0,0,a,a] ]</syntaxhighlight> |
| + | |
| + | |
| + | |
| + | Le script ci-dessous exploite l'affichage d'icône sous différentes formes: |
| + | # Affichage d'une icône simple. |
| + | # Affichage aléatoire d'une icône de façon aléatoire. |
| + | # Affichage d'une icône avec Canal Alpha. |
| | | |
− | Mise en place en dessinant une croix noir sur fond blanc.
| + | <syntaxhighlight lang="python">from machine import Pin, I2C |
− | <syntaxhighlight lang="python">cat icon.py | |
− | from machine import Pin, I2C | |
| import time | | import time |
| i2c = I2C( sda=Pin(4), scl=Pin(5) ) | | i2c = I2C( sda=Pin(4), scl=Pin(5) ) |
Ligne 316 : |
Ligne 361 : |
| time.sleep( 2 ) | | time.sleep( 2 ) |
| lcd.fill( 0 )</syntaxhighlight> | | lcd.fill( 0 )</syntaxhighlight> |
| + | |
| + | Ce qui produit les résultats suivants: |
| + | |
| + | [[Fichier:FEATHER-MICROPYTHON-OLED-20j.jpg|320px]] |
| + | |
| + | [[Fichier:FEATHER-MICROPYTHON-OLED-20k.jpg|320px]] |
| + | |
| + | [[Fichier:FEATHER-MICROPYTHON-OLED-20l.jpg|320px]] |
| + | |
| + | == Plus de ressources == |
| + | * [https://github.com/micropython/micropython/tree/master/drivers/display Pilotes d'afficheurs sur le GitHub MicroPython] |
| + | * [https://www.pymadethis.com/article/oled-displays-i2c-micropython/ Article PyMadeThis sur écran OLED ssd1603] |
| + | * [https://www.pymadethis.com/article/displaying-images-oled-displays/ Article PyMadeThis sur affichage d'image 2 couleurs] |
| | | |
| == Où acheter == | | == Où acheter == |
| * {{pl|846|Feather ESP8266}} | | * {{pl|846|Feather ESP8266}} |
| * {{pl|879|OLED FeatherWing 128x32 Pixels (ADA-2900) }} | | * {{pl|879|OLED FeatherWing 128x32 Pixels (ADA-2900) }} |