Ce programme permet d'actionner trois servo-moteurs (un servo-moteur pour la lèvre supérieure, un pour la lèvre inférieure et un pour les yeux).
'_______________ROBOT CHOUCHOU 3/2007______________
'__________Robots en balade - www.expo-robots.net__________
Const Device = cb220 'microcontrôleur CUBLOC CB220
Dim a As Integer 'boucle expressions de la bouche
Dim i As Byte 'boucle mouvement yeux
Dim touche As Byte 'appui touche
Dim alea As Integer
Low 5 'servo
Low 6 'servo
Low 7 'servo
'______________BOUCLE PRINCIPALE_________________
Do
Do
touche= Keyin(9,30) ' attente touche 9
Loop While touche=1 'valeur 1 provoque attente touche
'__________________DEMONSTRATION__________________
Gosub oeilgauche 'allumage LED pin 12 oeil
Gosub aléatoire 'mouvement aléatoire de la bouche"
Gosub mus1
Gosub oeildroite 'allumage LED pin 4 Gosub
Gosub triste
Gosub 2yeuxOFF 'extinction 2 yeux
delay 300
Gosub content
Gosub 2yeuxON 'allumage 2 yeux
Gosub yeuxgauche 'tourne à gauche lentement
Gosub aléatoire 'mouvement aléatoire de la bouche
Gosub yeuxdroite 'tourne à droite lentement
Gosub culdepoule
Gosub 2yeuxOFF 'extinction 2 yeux
gosub mus1
Gosub 2yeuxON 'allumage 2 yeux
Gosub yeuxNDGN 'servo yeux mouvement PWM 2 : pin 5
Gosub neutre
Gosub rectangle
Gosub trapèze
Gosub yeuxplus 'allumage progressif
Gosub mus1
Gosub 2yeuxON 'allumage 2 yeux
Gosub trapèze
Gosub progressif 'mouvement de la bouche progressif "triste à content"
Gosub yeuxplus
Gosub 2yeuxOFF 'extinction 2 yeux
Loop
'_____________________________________
triste:
For a = 1 To 1
Pwm 0, 1500,32768
Delay 400
Pwm 1, 3243,32768
Delay 400
Next
Return
'________________
content:
For a = 1 To 1
Pwm 0, 5000,32768
Delay 400
Pwm 1, 3900,32768
Delay 400
Next
Return
'_________________
culdepoule:
For a = 1 To 1
Pwm 0, 2000,32768
Delay 400
Pwm 1, 5000,32768
Delay 400
Next
Return
'_________________
neutre:
For a = 1 To 1
Pwm 0, 2850,32768
Delay 400
Pwm 1, 5200,32768
Delay 400
Next
Return
'_________________
rectangle:
For a = 1 To 1
Pwm 0, 4300,32768
Delay 400
Pwm 1, 3900,32768
Delay 400
Next
Return
'_________________
trapèze:
For a = 1 To 1
Pwm 0, 3300,32768
Delay 400
Pwm 1, 4200,32768
Delay 400
Next
Return
'_________________
'mouvement de la bouche progressif triste à content
progressif:
For a = 2000 To 4300 Step 20
Pwm 0, a , 32768
Pwm 1, a ,32768
Delay 20
Next
Pwmoff 0 ' stoppe canal impulsion PWM
Pwmoff 1 ' stoppe canal impulsion PWM
Delay 400
Return
'_________________
'mouvement aléatoire de la bouche
aléatoire:
For a = 1 To 1
alea = (rnd(0) / 10.25) + 2000
Pwm 0, alea , 32768 'plage aléatoire ~2000 à 5200
Delay 100
alea = (rnd(0) / 10.25) + 2000 'plage aléatoire ~2000 à 5200
Pwm 1, alea ,32768
Delay 10
Next
Delay 100
Pwmoff 0 ' stoppe canal impulsion PWM
Pwmoff 1 ' stoppe canal impulsion PWM
Return
'_________________
yeuxNGDN: 'positionnement des yeux servo mini ES-05
For a = 1 To 1
Pwm 2, 2650,32768 ' position neutre
Delay 200
Pwm 2, 1450,32768 ' position à gauche
Delay 200
Pwm 2, 5200,32768 ' position droite
Delay 400
Pwm 2, 2650,32768 ' position neutre
Delay 150
Next
Return
'_____
yeuxNDGN: 'positionnement des yeux servo mini ES-05
For a = 1 To 1
Pwm 2, 2650,32768 ' position neutre
Delay 200
Pwm 2, 5200,32768 ' position à droite
Delay 200
Pwm 2, 1450,32768 ' position gauche
Delay 400
Pwm 2, 2650,32768 ' position neutre
Delay 150
Next
Return
'_________________________________________
yeuxgauche: 'tourne à gauche lentement
Pwm 2, 2650,32768 'position neutre
Delay 200
For a = 2650 To 5200
Pwm 2, a,32768 'position à GAUCHE
Next
Return
'_________________________________
yeuxdroite: 'tourne à droite lentement
Pwm 2, 2650,32768 'position neutre
Delay 400
Pwm 2, 1500,32768
Delay 400
For a = 1500 To 2650
Pwm 2, a,32768
Next
Return
'_______________________________
'Allumage des yeux LED pin 12&4
oeilgauche:
For i = 1 To 20
Out 12,1 'gauche
Delay 20
Out 12,0 'gauche
Delay 15
Next
Return
'__________
oeildroite:
For i = 1 To 20
Out 4,1 'droite
Delay 14
Out 4,0 'droite
Delay 15
Next
Return
'____________________________
'ON oeil gauche & oeil droite
2yeuxON:
Out 12,1 'gauche
Out 4,1 'droite
Delay 150
Return
'_____________________________
'OFF oeil gauche & oeil droite
2yeuxOFF:
Out 12,0 'gauche
Out 4,0 'droite
Delay 100
Return
'_____________________________
'ON oeil progressif gauche & oeil droite
yeuxplus:
For i = 1 To 40
Out 12,1 'gauche
Out 4,1 'droite
Delay i
Out 12,0
Out 4,0
Delay i * 2
Next
Return
'________________________
'MUSIQUE
mus1:
Low 8
Out 15,1 'activation relais HP
Delay 10
For a = 1 To 6
Pulsout 8, 1
Pulsout 8, 20 * a
Next
Out 15, 0 'coupe le relais de commande HP
Return
'______________________