44 lines
785 B
C++
Executable File
44 lines
785 B
C++
Executable File
int motor1 = 6;
|
|
int motor2 = 7;
|
|
int cambio = 2; // Pin ligado a interrupcion 0
|
|
volatile boolean sentido = true;
|
|
int espera = 500;
|
|
|
|
void setup() {
|
|
//pinMode(cambio, INPUT);
|
|
pinMode(motor1, OUTPUT);
|
|
pinMode(motor2, OUTPUT);
|
|
attachInterrupt(0, cambioGiro, RISING);
|
|
}
|
|
|
|
void giro() {
|
|
if(sentido) {
|
|
digitalWrite(motor2, LOW);
|
|
digitalWrite(motor1, HIGH);
|
|
} else if(!sentido) {
|
|
digitalWrite(motor1, LOW);
|
|
digitalWrite(motor2, HIGH);
|
|
} else {
|
|
digitalWrite(motor1, LOW);
|
|
digitalWrite(motor2, LOW);
|
|
}
|
|
}
|
|
|
|
void cambioGiro() {
|
|
digitalWrite(motor1, LOW);
|
|
digitalWrite(motor2, LOW);
|
|
sentido = !sentido;
|
|
}
|
|
|
|
void detener() {
|
|
digitalWrite(motor1, LOW);
|
|
digitalWrite(motor2, LOW);
|
|
}
|
|
|
|
void loop() {
|
|
detener();
|
|
delay(espera);
|
|
giro();
|
|
delay(5000);
|
|
}
|