Modifications

Sauter à la navigation Sauter à la recherche
3 260 octets ajoutés ,  20 octobre 2015 à 19:58
Ligne 68 : Ligne 68 :     
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Matrice-10.jpg]]
 
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Matrice-10.jpg]]
 +
 +
This is how all computer and smartphone screens work. If you want to make recognisable shapes on the LED matrix this is what you also need to do. You only have a resolution of 8 by 8 pixels to work with on the Sense HAT LED matrix though, so you must make shapes and icons that will look quite blocky. This can be a nice challenge!
 +
 +
'''1.''' Select {{fname|File > New Window}} (''Fichier > Nouvelle fenêtre'').
 +
 +
'''2.''' Type in the following code:
 +
 +
<nowiki>from sense_hat import SenseHat
 +
 +
sense = SenseHat()
 +
 +
sense.clear()
 +
 +
x = 0
 +
y = 0
 +
 +
sense.set_pixel(x, y, 255, 255, 255)</nowiki>
 +
 +
'''3.''' Select {{fname|File > Save}} and choose a file name for your program.
 +
 +
'''4.'''Then select {{fname|Run > Run module}} (''Executer > Executer le module'').
 +
 +
'''5.''' This will turn one LED in the corner white.
 +
 +
'''6.''' Remember that you can change the colour if you wish.
 +
 +
== Activer un pixel avec les coordonnées ==
 +
The {{fname|x}} and {{fname|y}} variables can be used to control which individual LED the {{fname|set_pixel}} command should change. '''X''' is horizontal and ranges from {{fname|0}} on the left to {{fname|7}} on the right. '''Y''' is vertical and ranges from {{fname|0}} at the top to {{fname|7}} on the bottom. Therefore, an {{fname|x, y}} coordinate of {{fname|0, 0}} is the top left and an {{fname|x, y}} coordinate of {{fname|7, 7}} is the bottom right.
 +
 +
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Matrice-11.png]]
 +
 +
You can get a different colour in each corner of the LED matrix. You will need to use the set_pixel command multiple times in your code like this:
 +
 +
<nowiki>from sense_hat import SenseHat
 +
 +
sense = SenseHat()
 +
 +
sense.clear()
 +
sense.set_pixel(0, 0, 255, 0, 0)
 +
sense.set_pixel(0, 7, 0, 255, 0)
 +
sense.set_pixel(7, 0, 0, 0, 255)
 +
sense.set_pixel(7, 7, 255, 0, 255)</nowiki>
 +
 +
== Afficher des formes ==
 +
You may be tempted to try and draw shapes or patterns using the {{fname|set_pixel}} command over and over in your code. There is a {{fname|set_pixels}} command though, and with it you can change all 64 LEDs using one line of code! For example, you could draw a Minecraft creeper face on the LED Matrix:
 +
 +
<nowiki>from sense_hat import SenseHat
 +
 +
sense = SenseHat()
 +
 +
O = (0, 255, 0) # Green
 +
X = (0, 0, 0) # Black
 +
 +
creeper_pixels = [
 +
    O, O, O, O, O, O, O, O,
 +
    O, O, O, O, O, O, O, O,
 +
    O, X, X, O, O, X, X, O,
 +
    O, X, X, O, O, X, X, O,
 +
    O, O, O, X, X, O, O, O,
 +
    O, O, X, X, X, X, O, O,
 +
    O, O, X, X, X, X, O, O,
 +
    O, O, X, O, O, X, O, O
 +
]
 +
 +
sense.set_pixels(creeper_pixels)</nowiki>
 +
 +
You can even use more than two colours, like in this example of Steve from Minecraft:
 +
 +
<nowiki>from sense_hat import SenseHat
 +
 +
sense = SenseHat()
 +
 +
B = (102, 51, 0)
 +
b = (0, 0, 255)
 +
S = (205,133,63)
 +
W = (255, 255, 255)
 +
 +
steve_pixels = [
 +
    B, B, B, B, B, B, B, B,
 +
    B, B, B, B, B, B, B, B,
 +
    B, S, S, S, S, S, S, B,
 +
    S, S, S, S, S, S, S, S,
 +
    S, W, b, S, S, b, W, S,
 +
    S, S, S, B, B, S, S, S,
 +
    S, S, B, S, S, B, S, S,
 +
    S, S, B, B, B, B, S, S
 +
]
 +
 +
sense.set_pixels(steve_pixels)</nowiki>
 +
 +
== Charger une image depuis un fichier ==
 +
Instead of setting the LED matrix, you may wish to use images which are loaded from files. This is a convenient option if you want to have lots of stock images, for example international flags.
 +
       
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
29 917

modifications

Menu de navigation