buen dia comunidad , lo que trato de realizar es que al presionar el push botton en automatico me activen los dos leds y el buzzer por 30 segundos y que el servomotor realize un giro de 90° y que ese angulo giro permanezca mientras transcurren los 30 segundos pasado ese tiempo se desactiva todo, hasta que se presione de nuevo el push
#include <Servo.h>
const int buzzer = 8; // PIN DEL BUZZER
const int botonPin = 2; // PIN DEL BOTON
const int led1Pin = 3; // PIN DEL PRIMER LED
const int led2Pin = 4; // Pin DEL SEGUNDO LED
const int tiempoParpadeo = 30000; // 30 segundos en milisegundos
const int tiempoParpadeoIndividual = 500; // Tiempo de parpadeo individual (500 ms)
Servo myservo;
bool parpadeando = false;
unsigned long tiempoInicioParpadeo = 0;
void setup() {
myservo.attach(9);
pinMode(botonPin, INPUT_PULLUP); // CONFIGURANDO BOTON COMO UNA ENTRADA
pinMode(led1Pin, OUTPUT); // // CONFIGURANDO LEDS COMO SALIDA
pinMode(led2Pin, OUTPUT); // // CONFIGURANDO LEDS COMO SALIDA
pinMode(buzzer, OUTPUT); // // CONFIGURANDO BUZZER COMO SALIDA
}
void loop() {
if (digitalRead(botonPin) == LOW) { // Si el botón está presionado
if (!parpadeando) {
parpadeando = true;
tiempoInicioParpadeo = millis();
}
myservo.write(90); // botón pulsado -> servo a 90°
} else {
myservo.write(0); // botón no pulsado -> servo a 0°
}
if (parpadeando) {
if (millis() - tiempoInicioParpadeo < tiempoParpadeo) { // Si ha pasado menos de 30 segundos
if (millis() % tiempoParpadeoIndividual < tiempoParpadeoIndividual / 2) { // Parpadeo individual (500 ms)
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, HIGH);
digitalWrite(buzzer, HIGH);
//myservo.write(90);
} else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(buzzer, LOW);
// myservo.write(0);
}
} else {
parpadeando = false;
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(buzzer, LOW);
//myservo.write(0);
}
} else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(buzzer, LOW);
//myservo.write(0);
}
}
me podrias guiar en esta ultima parte , Mueve el servo a 90° cuando pones la variable parpadeando en true y a 0° cuando la pones en false , segun yo realize la modificacion y sin antes de apretar el boton este ya realizo un giro , se que no es excusa apenas me voy agarrando en este mundo del arduino