Paso 8: Software Motor
Este bosquejo es cargado en el Arduino que tiene un escudo del motor en la parte superior.
Tenga en cuenta que el "salto = 1" se traslada a la segunda parte del programa, donde el robot persigue a la rana. La primera parte del programa se utiliza para activar al robot a moverse sin atascarse (una mejora futura--próximamente).
int val = 0;
int val1 = 0; Chi de int = 0; int valm1 = 0; salto de int = 1;
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;
void setup() {pinMode (dirA, salida); pinMode (plegadoraUna, salida); pinMode (dirB, salida); pinMode (brakeB, salida); pinMode(right,INPUT); pinMode(left,INPUT); digitalWrite (dirA, alto); //forward A digitalWrite (plegadoraUna, baja); //release plegadoraUna analogWrite (pwmA, 100); //set velocidad A digitalWrite (dirB, alto); digitalWrite(brakeB,LOW) motor //forward B; / / analogWrite (pwmB, 100); //set velocidad B delay(700);
}
void loop () {si (salto == 0) {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); delay (700) //backup digitalWrite (plegadoraUna ALTO); //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); }}} //jump uno analogWrite(pwmA,0) igual; analogWrite(pwmB,0); Val=digitalRead(right); val1=digitalRead(left); Si (val == alto & & val1 == HIGH) {analogWrite(pwmA,140); analogWrite(pwmB,140); delay(1000);} si (val == HIGH & & val1 == baja) {analogWrite (pwmA, 140); analogWrite(pwmB,50); delay(1000);} si (val1 == HIGH & & val == LOW) {analogWrite(pwmB,140); analogWrite(pwmA,50); delay(1000);}
}