#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
#define Pino_Servo1 5
#define Pino_Servo2 9
#define Pino_Servo3 12
#define Pino_Servo4 13
#define Pot A3
#define Pino_Botao 2
int seletor = 1;
void setup() {
servo1.attach(Pino_Servo1);
servo2.attach(Pino_Servo2);
servo3.attach(Pino_Servo3);
servo4.attach(Pino_Servo4);
pinMode(Pino_Botao, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Pino_Botao), seleciona, FALLING);
}
void loop() {
switch (seletor) {
case 1:
Servo1();
break;
case 2:
Servo2();
break;
case 3:
Servo3();
break;
case 4:
Servo4();
break;
}
}
void seleciona() {
seletor++;
if (seletor > 4)
{
seletor = 1;
}
}
void Servo1()
{
servo1.write(map(analogRead(Pot), 0, 1023, 0, 180));
}
void Servo2()
{
servo2.write(map(analogRead(Pot), 0, 1023, 0, 180));
}
void Servo3()
{
servo3.write(map(analogRead(Pot), 0, 1023, 0, 180));
}
void Servo4()
{
servo4.write(map(analogRead(Pot), 0, 1023, 0, 180));
}