Modifications

Sauter à la navigation Sauter à la recherche
Ligne 57 : Ligne 57 :     
== Détecter les mouvements du joystick ==
 
== Détecter les mouvements du joystick ==
{{traduction}}
+
Voyons comment un joystick fonctionne, nous pouvons utiliser la matrice LED pour nous aider à le comprendre.
 +
 
 +
Nous allons utiliser un point blanc (un pixel) et utiliser le joystick pour le déplacer sur la matrice 8x8. Pour réaliser ce tâche, nous pouvons utiliser un événement qui détecte la pression d'une touche. Par exemple, si la touche BAS (''DOWN'' en anglais) est pressée, nous allons déplacer le point allumé vers le bas.
   −
Consider how a joystick might work. You can use the LED matrix to help you think about it. Let's make a pixel white and use the joystick to move the pixel around the 8x8 matrix. To do this you can use an event to detect a key press. For example, if a key is pressed DOWN what steps need to happen to move the pixel?
+
A votre avis, comment allons nous gérer cela?  
   −
  <nowiki>- Turn OFF the LED using current `x` and `y`
+
  <nowiki>Lorsqu'un événement touche enfoncée est détecté?
- If DOWN then add 1 to `y`
+
- Eteindre la LED située à la position 'x' et 'y' actuelle
- If UP then subtract 1 from `y`
+
- Si '''DOWN''' (''bas'') est détecté alors ajouter 1 à 'y'
- If RIGHT then add 1 to `x`
+
- Si '''UP''' (''haut'') est détecté alors soustraire 1 à 'y'
- If LEFT then subtract 1 from `x`
+
- Si '''RIGHT''' (''droite'') est détecté alors ajouter 1 à 'x'
- Turn ON the LED using updated `x` and `y`</nowiki>
+
- Si '''LEFT''' (''gauche'') est détecté alors soustraire 1 à 'x'
 +
- Allumer la LED sur la nouvelle coordonnée 'x' et 'y' que nous venons de calculer</nowiki>
      −
'''1.''' Start by just adding the code for the DOWN key. Delete the {{fname|print(event)}} command that you used in the previous section and insert the code below at the same indentation level:
+
'''1.''' Commençons par ajouter le code prennant en charge la touche vers le bas ('''DOWN'''). Effacez la ligne {{fname|print(event)}} que nous avons utilisé dans la section précédente et insérez le code ci-dessous au même niveau d'indentation:
    
  <nowiki>if event.type == KEYDOWN:
 
  <nowiki>if event.type == KEYDOWN:
     sense.set_pixel(x, y, 0, 0, 0)  # Black 0,0,0 means OFF
+
     sense.set_pixel(x, y, 0, 0, 0)  # Noir = 0,0,0 - ce qui éteind la LED
    
     if event.key == K_DOWN:
 
     if event.key == K_DOWN:
Ligne 79 : Ligne 82 :  
         sense.set_pixel(x, y, 255, 255, 255)</nowiki>
 
         sense.set_pixel(x, y, 255, 255, 255)</nowiki>
   −
'''2.''' Save and run the code. You should be able to move the pixel point down using the {{fname|DOWN}} key or the joystick. If you keep going, you'll eventually see this error:
+
'''2.''' Sauvez et exécutez le code. Vous devriez être capable de déplacer un pixel vers le bas en utilisant la touche {{fname|DOWN}} (''flèche vers le bas'') ou le joystick. Si vous continuez, vous rencontrez éventuellement cette erreur:
    
  <nowiki>ValueError: Y position must be between 0 and 7</nowiki>
 
  <nowiki>ValueError: Y position must be between 0 and 7</nowiki>
 +
 +
Signifiant que la valeur pour la position Y doit être comprise entre 0 et 7.
 +
 +
{{traduction}}
    
'''3.''' Our {{fname|y}} value can only be between 0-7, otherwise it's off the edge of the matrix and into empty space! So that's why the error happens; the Sense HAT doesn't understand values outside this range. Our code just keeps adding 1 to {{fname|y}} every time the DOWN key is pressed, so we need to stop {{fname|y}} going above 7.
 
'''3.''' Our {{fname|y}} value can only be between 0-7, otherwise it's off the edge of the matrix and into empty space! So that's why the error happens; the Sense HAT doesn't understand values outside this range. Our code just keeps adding 1 to {{fname|y}} every time the DOWN key is pressed, so we need to stop {{fname|y}} going above 7.
29 918

modifications

Menu de navigation