R2D2

/*
** Prueba de motores del R2D2
** Copyright 216 Leonardo Yamasaki Maza
** Licencia GPL.
**/
 
#define MOTOR1P    2 //Pin Motor 1 positivo
#define MOTOR1N    3 //Pin Motor 1 negativo
#define MOTOR2P    4 //Pin Motor 2 positivo
#define MOTOR2N    5 //Pin Motor 2 negativo
 
 
/*
 * Control de motores
*/
 
void parar(){
  digitalWrite(MOTOR1P,LOW);
  digitalWrite(MOTOR1N,LOW);
  digitalWrite(MOTOR2P,LOW);
  digitalWrite(MOTOR2N,LOW);
}
 
void adelante(){
  digitalWrite(MOTOR1P,LOW);
  digitalWrite(MOTOR1N,HIGH);
  digitalWrite(MOTOR2P,HIGH);
  digitalWrite(MOTOR2N,LOW);
}
 
void atras(){
  digitalWrite(MOTOR1P,HIGH);
  digitalWrite(MOTOR1N,LOW);
  digitalWrite(MOTOR2P,LOW);
  digitalWrite(MOTOR2N,HIGH);
}
 
void derecha(){
  digitalWrite(MOTOR1P,HIGH);
  digitalWrite(MOTOR1N,LOW);
  digitalWrite(MOTOR2P,HIGH);
  digitalWrite(MOTOR2N,LOW);
}
 
void izquierda(){
  digitalWrite(MOTOR1P,LOW);
  digitalWrite(MOTOR1N,HIGH);
  digitalWrite(MOTOR2P,LOW);
  digitalWrite(MOTOR2N,HIGH);
}
 
void setup() {
  //Motores puente H
  pinMode(MOTOR1P,OUTPUT);
  pinMode(MOTOR1N,OUTPUT);
  pinMode(MOTOR2P,OUTPUT);
  pinMode(MOTOR2N,OUTPUT);
}
 
void loop() {
  adelante();
  delay(500);
  parar();
  delay(2000);
  atras();
  delay(500);
  parar();
  delay(2000);
 
  derecha();
  delay(500);
  parar();
  delay(2000);
  izquierda();
  delay(500);
  parar();
  delay(2000);
 
}