/* ESTE CODIGO SOLO INCLUYE LA ACCION CON UN BOTON Y SE
CONSTRUYE SOLO PARA SIMULAR LOS TIEMPOS Y ANGULOS DE INCIDENCIA
DEL SERVO MOTOR, EL CODIGO FINAL SE AMPLIARA E INCLUIRA A SIRICPRO
Y GOOGLE MINI HOME PARA MANEJAR EL DISPOSITIVO CON COMANDOS DE VOZ */
#include <Arduino.h>
#include <ESP32Servo.h> // Asegúrate de tener instalada esta librería
const int buttonPin = 13; // Pin donde está conectado el botón
const int servoPin = 26; // Pin donde está conectado el servo
//*******************PARAMETROS CONFIGURACION*******************
const int inicio=100;// Posicion desde donde comienza la palanca
const int final=70;// Desplazamiento del brazo o palanca
const int tiempo= 400;//Tiempo que se mantendra oprimido el brazo en el boton
//**************************************************************
Servo myServo;
int buttonState = inicio; // Estado actual del botón
int previousState = inicio; // Estado previo del botón
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Configurar el botón con resistencia pull-up
myServo.attach(servoPin); // Conectar el servo al pin definido
myServo.write(inicio); // Posición inicial del servo
Serial.begin(115200);
}
void loop() {
buttonState = digitalRead(buttonPin); // Leer el estado del botón
// Detectar un cambio de estado en el botón (presión)
if (buttonState == LOW && previousState == HIGH) {
Serial.println("Botón presionado, moviendo servo...");
// Mover el servo hacia adelante (ahora de final a inicio)
for (int pos = inicio; pos >= final; pos--) {
myServo.write(pos);
delay(15);
}
// Mover el servo hacia atrás (ahora de inicio a final)
for (int pos = final; pos <= inicio; pos++) {
myServo.write(pos);
delay(15);
}
}
previousState = buttonState; // Actualizar el estado previo del botón
}