Paso 7: código de
Cargar el código de abajo en el Arduino que controla los motores.
int costo = 0; int val = 0; int val1 = 0; Chi de int = 0; int valm1 = 0; int salto = 3; ctr de int = 0; //counter const int pwmA = 3; const int pwmB = 11; const int plegadoraUna = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; const int derecha = 5; const int izquierda = 7; const int chglt = 6; void setup() {pinMode (dirA, salida); pinMode (plegadoraUna, salida); pinMode (dirB, salida); pinMode (brakeB, salida); pinMode(right,INPUT); pinMode(left,INPUT) pinMode(chglt,OUTPUT); digitalWrite (dirA, alto); //forward A digitalWrite (plegadoraUna, baja); //release plegadoraUna analogWrite (pwmA, 100); //set velocidad A digitalWrite (chglt, HIGH); //test carga ligera digitalWrite (dirB, alto); digitalWrite(brakeB,LOW) motor //forward B; / / analogWrite (pwmB, 100); //set velocidad B delay(700); digitalWrite (chglt ,Low); //set cargar luz} void loop () {si (salto == 0) {analogWrite (pwmA, 0); //charge encontrar analogWrite(pwmB,0); digitalWrite(chglt,HIGH); delay(50000);} si (salto == 1) {valm=analogRead(0); valm1=analogRead(1); si (Chi > 500 o valm1 > 500) {valm=analogRead(0); valm1=analogRead(1); si (Chi > 450 o valm1 > 450) {digitalWrite (plegadoraUna, HIGH); digitalWrite (brakeB, HIGH); digitalWrite (dirA LOW); //reverse A digitalWrite (plegadoraUna, LOW); / / analogWrite (pwmA, 200); digitalWrite(dirB,LOW); digitalWrite(brakeB,LOW); analogWrite(pwmB,200); retardo (700) //backup digitalWrite (plegadoraUna, HIGH); //stop analogWrite(pwmA,0) de una rueda; Delay(1000); digitalWrite (brakeB, HIGH); //stop otros rueda //start dos ruedas adelante digitalWrite(dirA,HIGH); digitalWrite(brakeA,LOW); analogWrite(pwmA,140); digitalWrite(dirB,HIGH); digitalWrite(brakeB,LOW); analogWrite(pwmB,140); Delay(1000); }}} //find de la estación si (salto == 3) {analogWrite(pwmA,0); analogWrite(pwmB,0); val=digitalRead(right); val1=digitalRead(left); si (val == HIGH & & val1 == HIGH) {analogWrite(pwmA,140); analogWrite(pwmB,140); si (ctr < 150) {ctr = ctr + 1; carga = analogRead (2); //test para estación de carga if(charge>100) {saltar = 0; ctr = 5000;} if(ctr==150) {ctr = 0;}}} si (val == HIGH & & val1 == LOW) {analogWrite (pwmA 190); analogWrite(pwmB,50); Si (ctr < 150) {ctr = ctr + 1; carga = analogRead (2); //test para estación de carga if(charge>100) {saltar = 0; ctr = 5000;} if(ctr==150) {ctr = 0;}}} Si (val1 == alto & & val == LOW) {analogWrite(pwmB,190); analogWrite(pwmA,50); si (ctr < 150) {ctr = ctr + 1; carga = analogRead (2); //test para estación de carga if(charge>100) {saltar = 0; ctr = 5000;} if(ctr==150) {ctr = 0;}}}}}