/*
 Controlling a servo position using a potentiometer (variable resistor)
 by sergio valverde @sergio.mvp -- 14/03/2022
 have fun! :^)

This is a free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

*/

#include <Servo.h>
#define interruptPin 2
#define servoPin 3
#define maxLimitServo 170 //change this value 10 ->170 to adjust travel down
#define minLimitServo 30  //change this value 10 ->170 to adjust travel up

Servo myservo;  // create servo object to control a servo


void setup() {
  myservo.attach(servoPin);  // attaches the servo on servoPin to the servo object
  pinMode(interruptPin, INPUT_PULLUP); //pullup on interruptPin to avoid using pullup resistor

}

void loop() {

   int state;
  state = digitalRead(interruptPin);
  if (state==HIGH)
    myservo.write(maxLimitServo); //send down
  else{
    myservo.write(minLimitServo); //send up
  }
}






void clicked() {
  int state;
  state = digitalRead(interruptPin);
  if (state==HIGH)
    myservo.write(170); //manda pra baixo
  else
    myservo.write(30); //manda pra cima
}
