#include <Servo.h> // Incluimos la librería para controlar el servomotor
// Definimos los pines para el servomotor, potenciómetro y zumbador
const int potPin = A0; // Pin analógico para el potenciómetro
const int servoPin = 3; // Pin digital para el servomotor
const int rojo=13;
const int verde=12;
const int rosa=11;
const int azul=10;
const int amarillo=9;
const int blanco=8;
const int boton1=7;
const int boton2=6;
Servo myServo; // Creamos un objeto Servo
void setup() {
myServo.attach(servoPin); // Asociamos el servomotor al pin especificado
pinMode(rojo, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(rosa, OUTPUT);
pinMode(azul, OUTPUT);
pinMode(amarillo, OUTPUT);
pinMode(blanco, OUTPUT);
pinMode(boton1, INPUT);
pinMode(boton2, INPUT);
}
void loop() {
perilla();
botones();
}
void perilla(){
int potValue = analogRead(potPin); // Leemos el valor del potenciómetro (0 a 1023)
// Convertimos el valor del potenciómetro al rango de 0 a 180 grados
int angle = map(potValue, 0, 1023, 0, 180);
// Si el ángulo es mayor o igual a 90 grados, encendemos el zumbador
if (angle>10 && angle <15) {
digitalWrite(rojo, HIGH);
}
else if (angle>15 && angle <25) {
digitalWrite(verde, HIGH);
}
// estudiantes continuan
else {
digitalWrite(rojo, LOW);
digitalWrite(verde, LOW);
}
delay(15); // Esperamos para que el servomotor tenga tiempo de moverse
}
void botones(){
int estado1=digitalRead(boton1);
int estado2=digitalRead(boton2);
if(estado1==1){
myServo.write(40); //ajustamos el movimiento
}
else if (estado2==1){
myServo.write(80);
}
else{
myServo.write(0);
}
}