mirror of
https://forge.apps.education.fr/blender-edutech/blender-edutech-tutoriels.git
synced 2024-01-27 09:42:33 +01:00
Tutoriel 3 : manette 4 boutons achevée
This commit is contained in:
parent
370ae0174b
commit
5bce64a918
BIN
img/tuto1.jpg
Normal file
BIN
img/tuto1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 544 KiB |
BIN
img/tuto2.jpg
Normal file
BIN
img/tuto2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 565 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
labyrinthe/3-arduino/3-labyrinthe-manette-debut.blend
Normal file
BIN
labyrinthe/3-arduino/3-labyrinthe-manette-debut.blend
Normal file
Binary file not shown.
Binary file not shown.
@ -1,9 +1,10 @@
|
|||||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
import bge # Bibliothèque Blender Game Engine (BGE)
|
||||||
|
import pyfirmata # Protocole Firmata
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# 2-labyrinthe.py
|
# 3-labyrinthe-manette.py
|
||||||
# @title: Module (unique) de la scène 3D du labyrinthe à bille
|
# @title: Module (unique) de la scène 3D du labyrinthe à bille pilotable avec la manette
|
||||||
# @project: Blender-EduTech - Tutoriel : Tutoriel 2 Labyrinthe à bille - Passage au Python
|
# @project: Blender-EduTech - Tutoriel : Tutoriel 3 Labyrinthe à bille - Interfacer avec une carte Arduino
|
||||||
# @lang: fr
|
# @lang: fr
|
||||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||||
# @copyright: Copyright (C) 2023 Philippe Roy
|
# @copyright: Copyright (C) 2023 Philippe Roy
|
||||||
@ -23,6 +24,50 @@ JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|||||||
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
||||||
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Communication avec la carte Arduino
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# carte = pyfirmata.Arduino('COM4') # Windows
|
||||||
|
carte = pyfirmata.Arduino('/dev/ttyACM0') # GNU/Linux
|
||||||
|
print("Communication Carte Arduino établie")
|
||||||
|
|
||||||
|
# Iterateur pour les entrees
|
||||||
|
it = pyfirmata.util.Iterator(carte)
|
||||||
|
it.start()
|
||||||
|
|
||||||
|
# Definition des 4 boutons
|
||||||
|
bt_haut = carte.get_pin('d:2:i')
|
||||||
|
bt_bas = carte.get_pin('d:3:i')
|
||||||
|
bt_gauche = carte.get_pin('d:4:i')
|
||||||
|
bt_droit = carte.get_pin('d:5:i')
|
||||||
|
|
||||||
|
# led = carte.get_pin('d:13:o')
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Gestion de la manette Arduino
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def manette(cont):
|
||||||
|
obj = cont.owner # obj est l'objet associé au contrôleur donc 'Plateau'
|
||||||
|
resolution = 0.01
|
||||||
|
|
||||||
|
# Bouton haut - Broche 2
|
||||||
|
if bt_haut.read() == True and bt_bas.read() == False:
|
||||||
|
obj.applyRotation((-resolution,0,0), False)
|
||||||
|
|
||||||
|
# Bouton bas - Broche 3
|
||||||
|
if bt_haut.read() == False and bt_bas.read() == True:
|
||||||
|
obj.applyRotation((+resolution,0,0), False)
|
||||||
|
|
||||||
|
# Bouton gauche - Broche 4
|
||||||
|
if bt_gauche.read() == True and bt_droit.read() == False:
|
||||||
|
obj.applyRotation((0, -resolution,0), False)
|
||||||
|
|
||||||
|
# Bouton droit - Broche 5
|
||||||
|
if bt_gauche.read() == False and bt_droit.read() == True :
|
||||||
|
obj.applyRotation((0, resolution,0), False)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Gestion du clavier
|
# Gestion du clavier
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -34,6 +79,11 @@ def clavier(cont):
|
|||||||
keyboard = bge.logic.keyboard
|
keyboard = bge.logic.keyboard
|
||||||
resolution = 0.01
|
resolution = 0.01
|
||||||
|
|
||||||
|
# Touche ESC -> Quitter
|
||||||
|
if keyboard.inputs[bge.events.ESCKEY].status[0] == ACTIVATE:
|
||||||
|
carte.exit()
|
||||||
|
bge.logic.endGame()
|
||||||
|
|
||||||
# Flèche haut - Up arrow
|
# Flèche haut - Up arrow
|
||||||
if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE:
|
if keyboard.inputs[bge.events.UPARROWKEY].status[0] == ACTIVATE:
|
||||||
obj.applyRotation((-resolution,0,0), False)
|
obj.applyRotation((-resolution,0,0), False)
|
||||||
@ -127,7 +177,7 @@ def victoire_fermer(cont):
|
|||||||
scene.objects['Bille']['z']= -21 # On provoque le redémarrage si la bille est ressortie
|
scene.objects['Bille']['z']= -21 # On provoque le redémarrage si la bille est ressortie
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Gestion du Joystick
|
# Gestion du Joystick USB
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
def joystick(cont):
|
def joystick(cont):
|
||||||
|
@ -58,13 +58,13 @@ while True:
|
|||||||
##
|
##
|
||||||
|
|
||||||
if bt_a.read() == True and bt_r.read() == False:
|
if bt_a.read() == True and bt_r.read() == False:
|
||||||
print("X+")
|
print("Bouton haut")
|
||||||
if bt_a.read() == False and bt_r.read() == True:
|
if bt_a.read() == False and bt_r.read() == True:
|
||||||
print("X-")
|
print("Bouton bas")
|
||||||
if bt_g.read() == True and bt_d.read() == False:
|
if bt_g.read() == True and bt_d.read() == False:
|
||||||
print("Y+")
|
print("Bouton gauche")
|
||||||
if bt_g.read() == False and bt_d.read() == True :
|
if bt_g.read() == False and bt_d.read() == True :
|
||||||
print("Y-")
|
print("Bouton droit")
|
||||||
|
|
||||||
##
|
##
|
||||||
# Cadencement
|
# Cadencement
|
||||||
|
Loading…
Reference in New Issue
Block a user