#include <slowServo.h>
#include <mapper.h>
#include <mechButton.h>


// THIS CODE RELIES ON THE LC_baseTools & LC_slowServo libraries.
// those should be installed using the Arduino library manager.


slowServo   aServo(2);    // Create a slow servo given a pin number.
mechButton  theBtn(4);    // Create a mechanical button given a pin number.
int         savedDir;     // We'll need to save where we were heading.


void setup() {
  aServo.begin();                 // You need to call begin for each servo.
  aServo.setMsPerDeg(5);          // We want to go at least a tiny bit slower than WOT.
  theBtn.setCallback(btnClick);   // When the button changes state, call this function.
  savedDir = 180;                 // We'll start off heading to 180 deg.
}


// When button changes state, this is called.
void btnClick(void) {
  
  if (!theBtn.getState()) {             // Button clicked down.
    aServo.setDeg(savedDir);            // Set the servo direction.
  } else {                              // Button clicked up.
    savedDir = aServo.desiredDeg;       // Save what we were doing..
    aServo.stop();                      // Stop the servo.
  }  
}


void loop() {
  
  idle();                             // idle(); Runs everything.
  if (!theBtn.getState()) {           // Button held down!
    if (aServo.desiredDeg==180) {     // We heading to 180?
      if (aServo.currentDeg==180) {   // We already got there?
        aServo.setDeg(0);             // reverse to 0.
      }
    } else {                          // Oh, we're heading to zero?
      if (aServo.currentDeg==0) {     // And we already arrived?
        aServo.setDeg(180);           // Then head back to 180.
      }
    }
  }
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
servo1:GND
servo1:V+
servo1:PWM
Another example of the slowServo class.
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r