Você está na página 1de 3

//Pines de Entrada para Motor 1

const int enPin = 5; // H-Bridge enable pin


const int in11Pin = 2; // H-Bridge input pins
const int in12Pin = 3; // H-Bridge input pins
//Pines de Entrada para Motor 2
const int in21Pin = 4; // H-Bridge input pins
const int in22Pin = 5; // H-Bridge input pins
//Pines de Entrada para Motor 3
const int in31Pin = 6; // H-Bridge input pins
const int in32Pin = 7; // H-Bridge input pins
//Pines de Entrada para Motor 4
const int in41Pin = 8; // H-Bridge input pins
const int in42Pin = 9; // H-Bridge input pins
//Pines de Entrada para Motor 5
const int in51Pin = 10; // H-Bridge input pins
const int in52Pin = 11; // H-Bridge input pins
static int tiempo; // variable que recoge tiempo. Se define como static para pod
er utilizarla fuera de bucles
void setup() {
pinMode(in11Pin, OUTPUT);
pinMode(in12Pin, OUTPUT);

pinMode(in21Pin, OUTPUT);
pinMode(in22Pin, OUTPUT);

pinMode(in31Pin, OUTPUT);
pinMode(in32Pin, OUTPUT);

pinMode(in41Pin, OUTPUT);
pinMode(in42Pin, OUTPUT);

pinMode(in51Pin, OUTPUT);
pinMode(in52Pin, OUTPUT);
Serial.begin(9600); // Conecta con el Serial Monitor
}
void loop(){
for (tiempo=0;tiempo<44;tiempo=tiempo+1) { // bucle contador en dcimas de segun
do

Serial.println(tiempo);

//Motor 1
if(tiempo>=3 && tiempo<=6)
{
Serial.println("Motor 1, Posicion: A");
digitalWrite(in11Pin,LOW);
digitalWrite(in12Pin,HIGH);
}
if(tiempo>=7 && tiempo<=10)
{

Serial.println("Motor 1, Posicion: B");
digitalWrite(in11Pin,HIGH);
digitalWrite(in12Pin,LOW);

}
if(tiempo<3 || tiempo>10)
{
Serial.println("Motor 1, Detenido");
digitalWrite(in11Pin,LOW);
digitalWrite(in12Pin,LOW);
}


//Motor 2
if(tiempo>=11 && tiempo<=14)
{
Serial.println("Motor 2, Posicion: A");
digitalWrite(in21Pin,LOW);
digitalWrite(in22Pin,HIGH);
}
if(tiempo>=15 && tiempo<=18)
{
Serial.println("Motor 2, Posicion: B");
digitalWrite(in21Pin,HIGH);
digitalWrite(in22Pin,LOW);
}
if(tiempo<11 || tiempo>18)
{
Serial.println("Motor 2, Detenido");
digitalWrite(in21Pin,LOW);
digitalWrite(in22Pin,LOW);
}



//Motor 3
if(tiempo>=19 && tiempo<=22)
{
Serial.println("Motor 3, Posicion: A");
digitalWrite(in31Pin,LOW);
digitalWrite(in32Pin,HIGH);
}
if(tiempo>=23 && tiempo<=26)
{
Serial.println("Motor 3, Posicion: B");
digitalWrite(in31Pin,HIGH);
digitalWrite(in32Pin,LOW);
}
if(tiempo<19 || tiempo>26)
{
Serial.println("Motor 3, Detenido");
digitalWrite(in31Pin,LOW);
digitalWrite(in32Pin,LOW);
}


//Motor 4
if(tiempo>=27 && tiempo<=30)
{
Serial.println("Motor 4, Posicion: A");
digitalWrite(in41Pin,LOW);
digitalWrite(in42Pin,HIGH);
}
if(tiempo>=31 && tiempo<=34)
{
Serial.println("Motor 4, Posicion: B");
digitalWrite(in41Pin,HIGH);
digitalWrite(in42Pin,LOW);
}
if(tiempo<27 || tiempo>34)
{
Serial.println("Motor 4, Detenido");
digitalWrite(in41Pin,LOW);
digitalWrite(in42Pin,LOW);
}

//Motor 5
if(tiempo>=35 && tiempo<=39)
{
Serial.println("Motor 5, Posicion: A");
digitalWrite(in51Pin,LOW);
digitalWrite(in52Pin,HIGH);
}
if(tiempo>=40 && tiempo<=44)
{
Serial.println("Motor 5, Posicion: B");
digitalWrite(in51Pin,HIGH);
digitalWrite(in52Pin,LOW);
}
if(tiempo<35 || tiempo>44)
{
Serial.println("Motor 5, Detenido");
digitalWrite(in51Pin,LOW);
digitalWrite(in52Pin,LOW);
}

delay(1000);
};

delay(1000);
}

Você também pode gostar