blender-edutech-ressources-.../Lycee/Programmation Python/Jumeaux numériques/portail_coulissant/v1.2/porcou_cmd-test_thread.py

72 lines
2.3 KiB
Python

import bge # Bibliothèque Blender Game Engine (UPBGE)
from porcou_lib import * # Bibliothèque portail coulissant
###############################################################################
# porcou_cmd.py
# @title: Commandes du portail coulissant
###############################################################################
###############################################################################
# Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
###############################################################################
threads=[]
scene = bge.logic.getCurrentScene()
def start():
thread_start(threads, commandes)
def stop():
thread_stop(threads)
###############################################################################
# Instructions élémentaires pour le portail coulissant
#
# Actions (ordre = True ou False) :
# - Gyrophare : gyr (True|False)
# - Ouvrir le portail (moteur sens trigo) : mot_o (True|False)
# - Fermer le portail (moteur sens horaire) : mot_f (True|False)
# - Emetteur pour le capteur barrage IR : ir_emet(True|False)
#
# Capteurs (valeur retournée = True ou False) :
# - Capteur fin de course portail ouvert : fc_o()
# - Capteur fin de course portail fermé : fc_f()
# - Capteur barrage IR (absence d'obstacle) : ir_recep()
#
# Pupitre (valeur retournée = True ou False) :
# - Bouton poussoir coté rue : bp_ext()
# - Bouton poussoir coté cour : bp_int()
#
# Gestion du temps :
# - Temporisation en seconde : tempo(duree)
#
###############################################################################
def commandes():
# Coder vos commandes ici ...
# Exemple de code
while True:
# Clignoter 2x avec le bouton coté rue
if bp_ext() == True:
for i in range (2):
gyr(True)
tempo(0.5)
gyr(False)
tempo(0.5)
break
# Clignoter sans fin avec le bouton coté cours
if bp_int() == True:
while True:
gyr(True)
tempo(1)
gyr(False)
tempo(1)
break
print ("Thread #", len(threads)-1, "arrivé au bout -> fermeture.") # Tâche close (thread) << NE PAS MODIFIER CETTE LIGNE >>
scene.objects['Systeme']['thread_run']=False # Fin du cycle << NE PAS MODIFIER CETTE LIGNE >>