| Ligne 141 : |
Ligne 141 : |
| | lcd.fill_rect( 10,10, 20, 4, 0 ) | | lcd.fill_rect( 10,10, 20, 4, 0 ) |
| | lcd.show() # Afficher! | | lcd.show() # Afficher! |
| | + | </syntaxhighlight> |
| | + | |
| | + | [[Fichier:FEATHER-MICROPYTHON-MOD-OLED-20a.jpg|320px]] |
| | + | |
| | + | ==== Dessiner une image ==== |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | from machine import Pin, I2C |
| | + | import time |
| | + | i2c = I2C( sda=Pin(2), scl=Pin(4) ) |
| | + | import ssd1306 |
| | + | lcd = ssd1306.SSD1306_I2C( 128, 64, i2c ) |
| | + | lcd.fill( 0 ) |
| | + | lcd.show() |
| | + | |
| | + | # a: Alpha Channel (pas dessiné) |
| | + | a = None |
| | + | FB_ICON = [ |
| | + | [a,a,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,a,a], |
| | + | [a,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,a], |
| | + | [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], |
| | + | [1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], |
| | + | [1,0,0,1,0,1,1,1,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], |
| | + | [1,0,0,1,0,0,1,1,0,0,1,1,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], |
| | + | [1,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,a], |
| | + | [a,a,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,a,a] ] |
| | + | |
| | + | def draw_icon( lcd, from_x, from_y, icon ): |
| | + | for y, row in enumerate( icon ): |
| | + | for x, color in enumerate( row ): |
| | + | if color==None: |
| | + | continue |
| | + | lcd.pixel( from_x+x, |
| | + | from_y+y, |
| | + | color ) |
| | + | |
| | + | def randrange( max ): |
| | + | assert max < 256 |
| | + | import urandom |
| | + | r = urandom.getrandbits(8) |
| | + | while r > max: |
| | + | r = urandom.getrandbits(8) |
| | + | return r |
| | + | |
| | + | def random_icon( lcd, icon, count ): |
| | + | range_x = lcd.width - len(icon[0]) |
| | + | range_y = lcd.height - len(icon) |
| | + | for i in range( count ): |
| | + | draw_icon( lcd, |
| | + | randrange( range_x ), |
| | + | randrange( range_y ), |
| | + | icon |
| | + | ) |
| | + | |
| | + | # affichage de 30 icones (avec canal Alpha ) |
| | + | lcd.fill( 0 ) |
| | + | for i in range( 8 ): |
| | + | random_icon( lcd, FB_ICON, 1 ) |
| | + | lcd.show() |
| | + | |
| | + | time.sleep( 2 ) |
| | + | lcd.fill( 0 ) |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| | [[Fichier:FEATHER-MICROPYTHON-MOD-OLED-20a.jpg|320px]] | | [[Fichier:FEATHER-MICROPYTHON-MOD-OLED-20a.jpg|320px]] |