Modifications

Sauter à la navigation Sauter à la recherche
546 octets ajoutés ,  19 mars 2017 à 15:15
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{RASP-FT232H-NAV}}
 
{{RASP-FT232H-NAV}}
  −
{{traduction}}
      
== FT232 en mode Bus SPI ==
 
== FT232 en mode Bus SPI ==
Ligne 206 : Ligne 204 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
{{traduction}}
+
Vous devriez voir les NeoPixels s'allumer et s'animer avec différentes couleurs.
   −
You should see the NeoPixels light up and animate with different colors.  Note that you might need to change the pixel_count variable in the main part of the program to match the number of pixels in your NeoPixel strip, circle, matrix, etc.
+
{{underline|note:}} vous pourriez avoir besoin de changer la valeur de la variable pixel_count dans la section "__main__" du programme pour que la valeur corresponde au nombre de pixels que vous avez dans votre montage.
   −
This code does a couple things at a high level. It first defines a class called NeoPixel_FT232H. This class contains some methods and state which control generating the NeoPixel signal with an FT232H board. The second part of the code uses the NeoPixel_FT232H class to animate the NeoPixels.
+
Ce code réalise plusieurs opérations de haut-niveau. Il commence par définir une classe nommée NeoPixel_FT232H. Cette classe contient les méthodes et les états nécessaires à la génération du signal NeoPixelavec la carte FT232H. La seconde partie du code utilise la classe NeoPixel_FT232H pour animer les NéoPixels.
   −
You actually don't need to fully understand the NeoPixel_FT232H class code to use it. This code performs the 'oversampling' by using a lookup table to expand each byte of color data into 8 bytes of SPI data that approximates the NeoPixel control signal. The only important thing to know about the NeoPixel_FT232H class is that it exposes a '''set_pixel_color()''' function which allows you to set the red, green, and blue color value of a pixel.
+
Il n'est pas vraiment nécessaire de comprendre le code de la classe NeoPixel_FT232H pour pouvoir l'utiliser. Le code effectue un 'sur-échantillonnage' en utilisant une table de correspondance qui étend chaque octet/byte de couleur en enchaînement de 8 octets/bytes de donnée SPI (ce qui permet de faire une approximation du signal de contrôle NeoPixel). La seule chose vraiment importante à savoir à propos de de la classe NeoPixel_FT232H c'est qu'elle expose la méthode '''set_pixel_color()''' qui permet d'assigner la couleur (red,green,blue = rouge,vert,bleu) pour chaque pixel.
   −
Instead let's walk through a bit of the second half of the code that uses the NeoPixel_FT232H class:
+
Le plus intéressant se trouve dans la seconde partie du code, celle qui utilise la classe NeoPixel_FT232H:
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Run this code when the script is called at the command line:
+
# Python exécute le code ci-dessous lorsque le script est appelé en ligne de commande:
 
if __name__ == '__main__':
 
if __name__ == '__main__':
# Define the number of pixels in the NeoPixel strip.
+
# Défini le nombre de pixels utilisé dans le montage.
# Only up to ~340 pixels can be written using the FT232H.
+
# Capable de gérer jusqu'à environ 340 pixels via un FT232H.
 
pixel_count = 16
 
pixel_count = 16
# Create a NeoPixel_FT232H object.
+
# Créer un objet NeoPixel_FT232H.
 
pixels = NeoPixel_FT232H(pixel_count)
 
pixels = NeoPixel_FT232H(pixel_count)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
This portion of code has an if statement that checks if the program is being run from the command line before executing.  This is just a standard Python idiom for defining the main entry point of a program.
+
Cette portion de code contient une commande {{fname|if}} qui vérifie si le programme est lancé en ligne de commande (ou inclus dans un autre programme).
   −
Inside the if block you can see the number of pixels is defined and set in the pixel_count variable.  Then the NeoPixel_FT232H object is created by telling it that number of pixels as its only parameter.
+
C'est un idiom standard en python qui vérifie le mode de démarrage du script avant de l'exécuter.
    +
Dans le bloc {{fname|if}} you pouvez identifier la ligne qui définit le nombre de pixels (la valeur assignée à la variable ''pixel_count''). Ensuite, un objet NeoPixel_FT232H est créé en lui indiquant le nombre de LED disponibles).
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Animate each pixel turning red.
+
# Animation - allumer chaque pixel en rouge.
# Loop through each pixel.
+
# Passer chaque pixel en revue.
 
for i in range(pixel_count):
 
for i in range(pixel_count):
# Set the pixel color to pure red.
+
# Changer la couleur du pixel en rouge pure.
 
pixels.set_pixel_color(i, 255, 0, 0)
 
pixels.set_pixel_color(i, 255, 0, 0)
# Show the pixel buffer by sending it to the LEDs.
+
# Envoyer le buffer (de pixel) vers les LEDs.
 
pixels.show()
 
pixels.show()
# Delay for a short period of time.
+
# faire une toute petite pause.
 
time.sleep(0.25)
 
time.sleep(0.25)
# Animate each pixel turning pure green.
+
# Animation - allumer chaque pixel en vert pure.
 
for i in range(pixel_count):
 
for i in range(pixel_count):
 
pixels.set_pixel_color(i, 0, 255, 0)
 
pixels.set_pixel_color(i, 0, 255, 0)
 
pixels.show()
 
pixels.show()
 
time.sleep(0.25)
 
time.sleep(0.25)
# Animate each pixel turning pure blue.
+
# Animation - allumer chaque pixel en bleu pure.
 
for i in range(pixel_count):
 
for i in range(pixel_count):
 
pixels.set_pixel_color(i, 0, 0, 255)
 
pixels.set_pixel_color(i, 0, 0, 255)
Ligne 253 : Ligne 252 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
The next section performs a few simple animations that turn each pixel on with primary colors. You can see a loop is used to go through each pixel and the '''set_pixel_color()''' function is called to the pixel color.  This function takes 4 parameters, the first is the number of the pixel (start at 0), and the last 3 parameters are the red, green, and blue color componentsEach component should be a value from 0 to 255, where 0 is no color and 255 is maximum color intensity.
+
La section suivante réalise quelques animations simples. Elles allument chaque pixel dans une couleur primaire à l'aide de la fonction '''set_pixel_color()'''.   
   −
After changing the pixel color, the '''show()''' function is called to send the colors to the LEDs. You must call '''show()''' in order to make the NeoPixels light up with the colors you've set previously!
+
Cette fonction prend 4 paramètres:
 +
* Le premier est le n° du pixel à modifier (démarre à 0),  
 +
* Le deuxième est la quantité de ROUGE (valeur entre 0 et 255. 0 = pas de couleur, 255 = maximum d'intensité)  
 +
* Le deuxième est la quantité de VERT
 +
* Le deuxième est la quantité de BLEU
   −
Finally notice the '''time.sleep()''' function is used to delay for a short period of time (a quarter of a second in this case).  This sleep function is very useful for animating color changes that should go somewhat slowly.
+
Après chaque modification de Pixel, le code appelle la fonction '''show()'''. La fonction '''show()''' envoi l'état du buffer vers les NéoPixels. Nous avons donc une animation progressive du ruban.
 +
 
 +
Il est impératif d'appeler '''show()''' pour rafraîchir les données de couleur dans le ruban NéoPixel!
 +
 
 +
Pour finir, notez que la fonction '''time.sleep()''' est utilisé pour créer un délai de 1/4 seconde. Cela permet de réaliser l'allumage progressif du ruban (sous forme d'animation).
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
# Animate a pattern of colors marching around the pixels.
+
# Un modèle (pattern) de couleur qui se déplace le long des pixels.
# Create a pattern of colors to display.
+
# Creation du modele de couleur.
 
colors = [ (255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255),  
 
colors = [ (255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255),  
 
(0, 0, 255), (255, 0, 255) ]
 
(0, 0, 255), (255, 0, 255) ]
 
offset = 0
 
offset = 0
print 'Press Ctrl-C to quit.'
+
print 'Presser Ctrl-C pour quitter.'
 
while True:
 
while True:
# Loop through all the pixels and set their color based on the pattern.
+
# Passer tous les pixels en revue et fixer leur couleur en fonction du modèle.
 
for i in range(pixel_count):
 
for i in range(pixel_count):
 
color = colors[(i+offset)%len(colors)]
 
color = colors[(i+offset)%len(colors)]
 
pixels.set_pixel_color(i, color[0], color[1], color[2])
 
pixels.set_pixel_color(i, color[0], color[1], color[2])
 
pixels.show()
 
pixels.show()
# Increase the offset to make the colors change position.
+
# Incrementer le decalage (offset) pour changer la position des differentes couleurs.
 
offset += 1
 
offset += 1
 
time.sleep(0.25)
 
time.sleep(0.25)
 
</syntaxhighlight>
 
</syntaxhighlight>
   −
Finally the code enters an infinite loop where it animates a rainbow of colors marching across the pixels. This code uses the same '''set_pixel_color()''' function, but has a little extra logic to pick a color from a list and increase the offset of chosen colors every loop iteration. Also notice the '''show()''' function is again called after updating pixel colors in order to make the LEDs light up with the desired colors.
+
Pour finir, le code entre dans une boucle infinie qui anime un arc en clien progressant le long des pixels. Ce code utilise également la fonction '''set_pixel_color()''' mais avec une logique un peu plus élaborée qui sélectionne une couleur dans une liste de couleurs prédéfinies à chaque itération de la boucle.
 +
 
 +
Vous noterez également que la fonction '''show()''' est appelée pour faire une mise-à-jour du ruban avec la suite de couleur ainsi calculée.
 +
 
 +
La suite de couleur est décalée d'un pixel supplémentaire à chaque itération.
   −
That's all there is to controlling NeoPixels with SPI from the FT232H breakout!  Feel free to use the code above in your own NeoPixel projects!
+
Voila, c'est tout ce qu'il est nécessaire de savoir pour contrôler des NéoPixels depuis le bus SPI du breakout FT232H!
    
{{RASP-FT232H-TRAILER}}
 
{{RASP-FT232H-TRAILER}}
29 917

modifications

Menu de navigation