#include <Servo.h>;
#define SERVO_PIN 13 // Pin del servomotor
#define BOTON_ARR_PIN 14 // Pin del pulsador de subida
#define BOTON_ABA_PIN 27 // Pin del pulsador de bajada
#define POT_PIN 34 // Pin del potenciómetro
#define LDR_PIN 35 // Pin del LDR
Servo myServo;
int servoPos = 0; // Posición del servomotor
void setup() {
myServo.attach(SERVO_PIN);
pinMode(BOTON_ARR_PIN, INPUT_PULLUP);
pinMode(BOTON_ABA_PIN, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
// Control con pulsadores
if (digitalRead(BOTON_ARR_PIN) == LOW) {
servoPos += 10; // Aumentar la posición
if (servoPos > 180) servoPos = 180; // Limitar a 180
myServo.write(servoPos);
delay(200); // Debounce
}
if (digitalRead(BoTON_ABA_PIN) == LOW) {
servoPos -= 10; // Disminuir la posición
if (servoPos < 0) servoPos = 0; // Limitar a 0
myServo.write(servoPos);
delay(200); // Debounce
}
// Control con potenciómetro
int potValor = analogRead(POT_PIN);
servoPos = map(potValor, 0, 4095, 0, 180); // Mapear valor del potenciómetro
myServo.write(servoPos);
// Control con LDR
int ldrValor = analogRead(LDR_PIN);
if (ldrValor < 512) { // Ajusta el umbral según sea necesario
myServo.write(0); // Posición a 0 grados
} else {
myServo.write(180); // Posición a 180 grados
}
delay(100);
}