Modifications

Sauter à la navigation Sauter à la recherche
1 237 octets ajoutés ,  7 octobre 2015 à 20:39
Ligne 92 : Ligne 92 :     
'''5.''' Now that this works, you will need to add the other directions for the joystick. Where you have {{fname|1=if event.key == K_DOWN:}} in your code, you can also use:
 
'''5.''' Now that this works, you will need to add the other directions for the joystick. Where you have {{fname|1=if event.key == K_DOWN:}} in your code, you can also use:
 +
* {{fname|K_UP}} - Touche vers le haut
 +
* {{fname|K_DOWN}} - Touche vers le bas
 +
* {{fname|K_LEFT}} - Touche vers la gauche
 +
* {{fname|K_RIGHT}} - Touche vers la droite
 +
* {{fname|K_RETURN}} - Touche "''retour clavier''" ou "''entrée''".
 +
 +
'''6.''' We can add a section for each direction to complete your code:
 +
 +
<nowiki>import pygame
 +
 +
from pygame.locals import *
 +
from sense_hat import SenseHat
 +
 +
pygame.init()
 +
pygame.display.set_mode((640, 480))
 +
 +
sense = SenseHat()
 +
sense.clear()
 +
 +
running = True
 +
 +
x = 0
 +
y = 0
 +
sense.set_pixel(x, y, 255, 255, 255)
 +
 +
while running:
 +
    for event in pygame.event.get():
 +
        if event.type == KEYDOWN:
 +
            sense.set_pixel(x, y, 0, 0, 0)  # Black 0,0,0 means OFF
 +
 +
            if event.key == K_DOWN and y < 7:
 +
                y = y + 1
 +
            elif event.key == K_UP and y > 0:
 +
                y = y - 1
 +
            elif event.key == K_RIGHT and x < 7:
 +
                x = x + 1
 +
            elif event.key == K_LEFT and x > 0:
 +
                x = x - 1
 +
 +
        sense.set_pixel(x, y, 255, 255, 255)
 +
        if event.type == QUIT:
 +
            running = False
 +
            print("BYE")</nowiki>
 +
 +
'''7.''' When you run your code, you should now be able to move the pixel point anywhere on the matrix.
 +
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
29 918

modifications

Menu de navigation