Paso 3: Sketch de Arduino
Usa este código para probar el motor con la placa Arduino:
Si usted necesita PWM, sólo tiene que utilizar las salidas PWM de Arduino
y en lugar de digitalWrite, se debe utilizar el comando analogWrite
// ————————————————————————— Motors
int motor_left [] = {2, 3};
int motor_right [] = {7, 8};
int ledPin = 13; LED conectado al pin digital 13
// ————————————————————————— Setup
void setup() {}
Serial.Begin(9600);
Instalación de motores
int i;
para (i = 0; i < 2; i ++) {}
pinMode (motor_left [i], salida);
pinMode (motor_right [i], salida);
pinMode (ledPin, salida);
}
}
// ————————————————————————— Loop
void loop() {}
drive_forward();
Delay(1000);
motor_stop();
Serial.println("1");
drive_backward();
Delay(1000);
motor_stop();
Serial.println("2");
turn_left();
Delay(1000);
motor_stop();
Serial.println("3");
turn_right();
Delay(1000);
motor_stop();
Serial.println("4");
motor_stop();
Delay(1000);
motor_stop();
Serial.println("5");
digitalWrite (ledPin, HIGH); prende el LED
Delay(1000); Espere un segundo
digitalWrite (ledPin, LOW); fijar el LED apagado
Delay(1000); Espere un segundo
}
// ————————————————————————— Drive
void motor_stop() {}
digitalWrite (motor_left [0], LOW);
digitalWrite (motor_left [1], LOW);
digitalWrite (motor_right [0], LOW);
digitalWrite (motor_right [1], LOW);
Delay(25);
}
void drive_forward() {}
digitalWrite (motor_left [0], HIGH);
digitalWrite (motor_left [1], LOW);
digitalWrite (motor_right [0], HIGH);
digitalWrite (motor_right [1], LOW);
}
void drive_backward() {}
digitalWrite (motor_left [0], LOW);
digitalWrite (motor_left [1], HIGH);
digitalWrite (motor_right [0], LOW);
digitalWrite (motor_right [1], HIGH);
}
void turn_left() {}
digitalWrite (motor_left [0], LOW);
digitalWrite (motor_left [1], HIGH);
digitalWrite (motor_right [0], HIGH);
digitalWrite (motor_right [1], LOW);
}
void turn_right() {}
digitalWrite (motor_left [0], HIGH);
digitalWrite (motor_left [1], LOW);
digitalWrite (motor_right [0], LOW);
digitalWrite (motor_right [1], HIGH);
}