#include <Adafruit_SoftServo.h> // SoftwareServo (funciona em pinos não PWM)
#define INTERVALO_PISCA 150 // tempo para inversão do led
#define INTERVALO_ATUALIZA 10 //tempo para atualizar o servo: minimo 5
#define MINIMO 30 //meno valor 0
#define MAXIMO 149 //maior valor 179
Adafruit_SoftServo myServo1; //create TWO servo objects
int servoPos; // variable to convert voltage on pot to servo position
long int ultimaInversao = 0;
long int ultimaatualizacao = 0;
// Set up the interrupt that will refresh the servo for us automagically
OCR0A = 0xAF; // any number is OK
TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
myServo1.attach(SERVOPIN); // Attach the servo to pin 0 on Trinket
myServo1.write(1207); // Tell servo to go to position per quirk
delay(15); // Wait 15ms for the servo to reach the position
if ((millis() - ultimaatualizacao) > INTERVALO_ATUALIZA) //verifica se já deu o tempo para stualizar o servo
if(servoPos<=MINIMO) inc = 1;
else if(servoPos>=MAXIMO) inc = -1;
servoPos+=inc; //incrementa posição do Servo
myServo1.write(servoPos); // tell servo to go to position
ultimaatualizacao = millis();
if ((millis() - ultimaInversao) > INTERVALO_PISCA) //verifica se já deu o tempo para inverter o LED
digitalWrite(LED, !digitalRead(LED));
ultimaInversao = millis();
// We'll take advantage of the built in millis() timer that goes off
// to keep track of time, and refresh the servo every 20 milliseconds
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
// Called by the microcontroller every 2 milliseconds
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect) {
// this gets called every 2 milliseconds
// every 20 milliseconds, refresh the servos!