Paso 10: Arduino Script
Bien hecho si usted ha venido esto para nuestro viaje robótico, espero que haya comprendido las cosas hasta ahora y lo que usted no ha entendido le pidió aclaraciones o hizo su propia versión del elemento. Los ojos y la boca son los únicos elementos que funcionan únicamente con la placa arduino. Los otros elementos necesitan el proceso para controlarlos.
Script de Arduino
#include
int c = 0;
int pos = 0;
int talkmode = 0;
int oldtalkmode = 0; rfac largo;
mpos largo; int eyedel = 0;
pose de int = 140;
int poslip = 90;
int eyeposh = 57;
int eyeposhinc = 1;
int posbot = 90;
int stopy = 90;
Servo myservo; crear objeto servo para controlar un servo
se puede crear un máximo de ocho objetos de servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
Servo myservo7;
Servo myservo8;
int talkcount = 255;
eventualmente utilizar audio tope gatillo
int doclosemouth = 0;
int turnmode = 0;
int turnmode2 = 0;
int globmode = 1; es de 1 sobre 2 es 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); se fija el servo
myservo2.Attach(8); izquierda derecha
myservo3.Attach(5); hasta abajo
myservo4.Attach(3); ojos izquierdos y derecho
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)}
plantear = 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;
fuerza en este modo if(globmode==1) {}
movimiento if(talkmode==1) {}
espera para comienzo de hablar
{if(mystart==1)}
int salida = 0;
{while(analogRead(3)==0)}
updatestuff();
} mystart = 0; Serial.println("Hello"); }; Conde pausas
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;
plantear = 140;
poslip = 90;
posbot = 100;
if(pcount>5) {pcount = 0;
wcount ++;
doclosemouth = 1;
Serial.println(wcount);
pcount = 0;
plantear = 140;
poslip = 90;
posbot = 100;
mystart = 1;
} } //? } //? hablando / / delay(10+random(2));
pose=140+Random(60);
poslip=2+Random(32);
posbot=50+Random(30);
Delay (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 {}
núcleo bit if(doclosemouth==1) {mpos = 134;
plantear = 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;
plantear = 140;
poslip = 90;
posbot = 90;
myservo8.Write(100);
talkmode = 0;
} {if(talkmode==0)}
myservo6.Write(140);
myservo7.Write(90);
myservo8.Write(100);
plantear = 140;
poslip = 90;
posbot = 90;
MPOs = 132; cerrar la boca} si (turnmode > 9 & & turnmode < 70) {//left/ myservo2.write(turnmode) derecha; / / Serial.print("TM="+turnmode);
talkmode = oldtalkmode;
} if(turnmode2>70) {//left/ int derecha sv = turnmode2-70;
myservo3.Write(SV);
Serial.Print("TM="+turnmode);
talkmode = oldtalkmode;
} Si (MPO > 130 & & talkmode > 0) myservo4.write(57); arriba/abajo myservo.write(mpos) aquí;
} //end de globmode 1;
if(globmode==10) {//never = desactiva así 10 / / int v=analogRead(3);
if(v>20) {/ / globmode = 1;
talkmode = 1;
} updatestuff();
Inicio de ojo lazo 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/ myservo.write(135) de derecho;
myservo8.Write(Stopy);
myservo2.Write(turnmode);
Serial.Print("TM="+turnmode);
talkmode = oldtalkmode;
} Si (turnmode2 > 70 & & globmode == 1) {//left/ int derecha sv = turnmode2-70;
myservo3.Write(SV);
myservo6.Write(140);
myservo7.Write(90);
myservo8.Write(90);
Serial.Print("TM="+turnmode);
talkmode = oldtalkmode; } }