#include <Servo.h>
#include <OneButton.h>
#define MAX_SEROS 5
uint8_t n_sevo =MAX_SEROS;
uint8_t old_n_sevo =0;
Servo myServo[MAX_SEROS];
OneButton button1(A0, true);
void setup() {
for( int i=0; i<MAX_SEROS; i++)
{
myServo[i].attach( i + 2); // pin 22 up to 53 is 32 pins
}
button1.attachClick(click1);
}
void loop() {
button1.tick();
moveSevo();
}
void click1()
{
n_sevo++;
n_sevo=n_sevo%(MAX_SEROS+1);
}
void moveSevo()
{
if (old_n_sevo==n_sevo) return;
old_n_sevo=n_sevo;
if (n_sevo==MAX_SEROS)
{
for( int i=0; i<MAX_SEROS; i++) myServo[i].write(0);
return;
}
myServo[n_sevo].write(180);
}