Étape 10 : Arduino Script
Bravo si vous êtes venu pour notre voyage robotique, j’espère que vous avez compris les choses jusqu'à présent et ce que vous avez compris pas vous ont demandé des éclaircissements ou faites votre propre version de l’élément. Les yeux et la bouche sont les seuls éléments qui s’exécutent uniquement au large de la carte arduino. Les autres éléments ont besoin de traitement pour les contrôler.
Script de l’Arduino
#include
int c = 0 ;
int pos = 0 ;
int talkmode = 0 ;
int oldtalkmode = 0 ; rfac long ;
mpos long ; int eyedel = 0 ;
pose d’int = 140 ;
int poslip = 90 ;
int eyeposh = 57 ;
int eyeposhinc = 1 ;
int posbot = 90 ;
int stopy = 90 ;
Servo myservo ; Créez l’objet servo pour contrôler un servo
vous pouvez créer un maximum de huit objets de servo
Servo myservo2 ;
Servo myservo3 ;
Servo myservo4 ;
Servo myservo5 ;
Servo myservo6 ;
Servo myservo7 ;
Servo myservo8 ;
int talkcount = 255 ;
par la suite utiliser audio escale détente
int doclosemouth = 0 ;
int turnmode = 0 ;
int turnmode2 = 0 ;
int globmode = 1 ; 1 coup sur 2 est eyetwitch
int wcount ;
int pcount ;
mystart int = 1 ;
int notalkcount = 0 ;
void setup() {}
Serial.Begin(9600) ;
wcount = 0 ;
pCount = 0 ;
pinMode(1,OUTPUT) ;
pinMode(8,OUTPUT) ;
pinMode(5,OUTPUT) ;
pinMode(4,OUTPUT) ;
pinMode(13,OUTPUT) ;
pinMode(11,OUTPUT) ;
pinMode(10,OUTPUT) ;
pinMode(12,OUTPUT) ;
pinMode(3,OUTPUT) ;
pinMode(A3,OUTPUT) ;
pinMode(A4,OUTPUT) ;
myservo.Attach(1) ; attache le servo
myservo2.Attach(8) ; gauche à droite
myservo3.Attach(5) ; vers le bas jusqu'à
myservo4.Attach(3) ; yeux gauche et droit
myservo5.Attach(4) ;
myservo6.Attach(12) ;
myservo7.Attach(11) ;
myservo8.Attach(10) ;
int oldtalkmode = 0 ;
myservo3.Attach(a3) ;
myservo4.Attach(A4) ;
} void loop() {}
{if(talkmode==1)}
poser = 140 ;
poslip = 90 ;
posbot = 100 ; // }
if(MPOs>131) {}
notalkcount ++ ;
} else {}
notalkcount == 0 ;
//}
Serial.Print(notalkcount) ;
if(notalkcount>2000) {}
talkmode = 0 ;
oldtalkmode = 0 ;
notalkcount = 0 ; // } // }
int t=random(2000) ;
int pos=random(400) ;
if(t>1998) {if(pos>195) {int v=25+random(60) ;
int pos2=140+random(60) ;
myservo4.Write(v) ;
myservo5.Write(POS2) ;
} }
while(Serial.available() > 0) {int din=Serial.read() ;
if(talkmode<9) oldtalkmode = talkmode ;
if(DIN<8) talkmode = din ;
Si (din > 8 & & din < 70) turnmode = din ;
Si (din > 70 & & din < 201) turnmode2 = din ;
Si (din == 201 & & talkmode == 0) {}
globmode = 2 ;
MPOs = 134 ;
// }
Si (globmode = 1) ;
Serial.Print("TM="+talkmode) ;
{if(globmode==1)}
eyeposh = 57 ;
myservo4.Write(eyeposh) ;
// } }
globmode = 1 ;
force dans ce mode if(globmode==1) {
mouvement if(talkmode==1) {}
attendre début de parler
{if(MyStart==1)}
décrochage scolaire int = 0 ;
{while(analogRead(3)==0)}
updatestuff() ;
} mystart = 0 ; Serial.println("Hello") ; }; comte de pauses
if(MyStart==0) {int v=analogRead(3) ;
Serial.Print("v:") ;
Serial.Print(v) ;
Serial.Print("") ;
if(v==0) {pcount ++; if(pcount>10) {mystart = 1;}} else {doclosemouth = 0 ;
poser = 140 ;
poslip = 90 ;
posbot = 100 ;
if(pCount>5) {pcount = 0 ;
wcount ++ ;
doclosemouth = 1 ;
Serial.println(wcount) ;
pCount = 0 ;
poser = 140 ;
poslip = 90 ;
posbot = 100 ;
MyStart = 1 ;
} } //? } //? parler / / delay(10+random(2)) ;
pose=140+Random(60) ;
poslip=2+Random(32) ;
posbot=50+Random(30) ;
retard (100) ;
myservo6.Write(pose) ;
myservo7.Write(poslip) ;
myservo8.Write(posbot) ;
rfaC=Random(100) ;
if(rfaC<45) {}
MPOs=Random(130) ;
MPOs=99+Random(50) ;
Delay(60+Random(40)) ;
Delay(Random(11)) ;
}
} else {}
if(doclosemouth==1) du carottier {mpos = 134 ;
poser = 140 ;
poslip = 90 ;
posbot = 100 ;
myservo8.Write(100) ;
myservo6.Write(140) ;
myservo7.Write(90) ;
myservo8.Write(90) ;
}} int r=analogRead(5) ;
if(r<1000) {mpos = 133 ;
poser = 140 ;
poslip = 90 ;
posbot = 90 ;
myservo8.Write(100) ;
talkmode = 0 ;
} if(talkmode==0) {}
myservo6.Write(140) ;
myservo7.Write(90) ;
myservo8.Write(100) ;
poser = 140 ;
poslip = 90 ;
posbot = 90 ;
MPOs = 132 ; fermer la bouche} si (turnmode > 9 & & turnmode < 70) {//left/ droit myservo2.write(turnmode); / / Serial.print("TM="+turnmode) ;
talkmode = oldtalkmode ;
} if(turnmode2>70) {//left/ int droite sv = turnmode2-70 ;
myservo3.Write(SV) ;
Serial.Print("TM="+turnmode) ;
talkmode = oldtalkmode ;
} Si (mpos > 130 & & talkmode > 0) myservo4.write(57) ; haut/bas myservo.write(mpos) ici ;
} //end de globmode 1 ;
if(globmode==10) {//never = 10 alors désactive / / int v=analogRead(3) ;
if(v>20) {/ / globmode = 1 ;
talkmode = 1 ;
} updatestuff() ;
début des yeux boucle eyedel ++ ;
if(eyedel==1000) {eyedel = 0 ;
myservo4.Write(eyeposh) ;
eyeposh = eyeposh + eyeposhinc ;
Si (eyeposh == 90 || eyeposh == 25) {eyeposhinc = eyeposhinc *-1; int d = 250 ;
d=d+Random(1750) ;
Delay(d) ; } } } }
void updatestuff() {int t=random(2000) ;
if(t>1998) {int v=25+random(60) ;
myservo4.Write(v) ;
int pos=random(400) ;
if(pos>195) {int pos2=140+random(60) ;
myservo5.Write(POS2) ;
}} / / if(mpos>131) {//notalkcount++ ;
} else {/ / notalkcount == 0 ;
} //if(notalkcount>2000) {/ / talkmode = 0 ;
oldtalkmode = 0 ;
notalkcount = 0 ;
} while(Serial.available() > 0) {int din=Serial.read() ;
if(talkmode<9) oldtalkmode = talkmode ;
if(DIN<8) talkmode = din ;
if(DIN==1) {/ / globmode = 1 ;
talkmode = 1 ; eyeposh = 57 ;
myservo4.Write(eyeposh) ;
} Si (din > 8 & & din < 70) turnmode = din ;
Si (din > 70 & & din < 201) turnmode2 = din ;
Serial.Print("TM="+turnmode) ;
Si (din == 201 & & talkmode == 0) globmode = 2 ;
if(DIN==202) globmode = 1 ;
if(globmode==1) {/ / eyeposh = 57 ;
myservo4.Write(eyeposh) ;
}} Si (turnmode > 9 & & globmode == 1) {//left/ droit myservo.write(135) ;
myservo8.Write(STOPY) ;
myservo2.Write(turnmode) ;
Serial.Print("TM="+turnmode) ;
talkmode = oldtalkmode ;
} Si (turnmode2 > 70 & & globmode == 1) {sv droite int //left/ = turnmode2-70 ;
myservo3.Write(SV) ;
myservo6.Write(140) ;
myservo7.Write(90) ;
myservo8.Write(90) ;
Serial.Print("TM="+turnmode) ;
talkmode = oldtalkmode ; } }