Skip to content

demarrer avec un son

Victoria Vila edited this page Sep 10, 2018 · 9 revisions

Précédent | Home | Suivant

Ex 6.2 Démarrer avec un son

Exercice 6.2

Programme 1

Donnée

Écrivez un programme qui fasse démarrer le robot quand vous frappez dans vos mains et le fasse s’arrêter lorsque vous touchez un bouton

Thymio VPL

configuration empty

Code

# setup threshold for detecting claps
mic.threshold = 250
# reset outputs
call sound.system(-1)
call leds.top(0,0,0)
call leds.bottom.left(0,0,0)
call leds.bottom.right(0,0,0)
call leds.circle(0,0,0,0,0,0,0,0)

onevent buttons
when button.center == 1 do
motor.left.target = 0
motor.right.target = 0
emit pair_run 1
end


onevent mic
motor.left.target = 350
motor.right.target = 400
emit pair_run 0

Programme 2

Donnée

Écrivez un programme qui fasse l’opposé : le robot démarre lorsque vous touchez un bouton et s’arrête lorsque vous frappez dans vos mains.

Réponse

Le problème de ce programme est que le Thymio fait du bruit lorsqu'il démarre. Il s'éteint donc directement. La solution est de faire avancer le Thymio a une vitesse lente, ainsi le bruit des moteurs n'est pas détecter.

Thymio VPL

empty

Code

# setup threshold for detecting claps
mic.threshold = 250
# reset outputs
call sound.system(-1)
call leds.top(0,0,0)
call leds.bottom.left(0,0,0)
call leds.bottom.right(0,0,0)
call leds.circle(0,0,0,0,0,0,0,0)
	
onevent buttons
when button.center == 1 do
motor.left.target = 150
motor.right.target = 150
emit pair_run 0
end


onevent mic
motor.left.target = 0
motor.right.target = 0
emit pair_run 1

Clone this wiki locally