Toggle servos on/off using switches and Adafruit 16-channel PWM & Servo driver

Hello,

I'm trying to run multiple servos using the Adafruit 16-channel PWM & Servo driver. I want to have each servo run from 0° to 180° when a switch is toggled one way and then 180° to 0° when it's toggled the other way. The switches I'd like to use are passing contact switches in a 1-0-1 configuration.
I'm using the PWM shield because I need the servos to start off slow, run at full speed, and then slow down again.

The code I have so far is below. It currently does nothing except repeat the 2 "if" statements over and over and doesn't respond to my switches. (I've tried to cannibalise the Adafruit example code as well as the servo code included with the Arduino library).

Any ideas are really appreciated. No doubt I've not included something or am going about it completely the wrong way.

Thanks in advance,

Ben

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <Servo.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN 150
#define SERVOMAX 600

uint16_t servonum;
const int servo0up = 0;
const int servo0dn = 1;
double pulselength;
int degrees;

void setup()
  {
    pinMode(servo0up, INPUT);
    pinMode(servo0dn, INPUT);
    digitalWrite(servo0up, LOW);
    digitalWrite(servo0dn, LOW);
    pwm.setPWMFreq(60);
    pwm.setPWM(servonum, 1024, 3072);
    pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
  }

void loop()
  {
    if (digitalRead(servo0up) == HIGH);
    {
      servonum = 0;
      pulselength = 180;
    }

    if (digitalRead(servo0dn) == HIGH);
    {
      servonum = 0;
      pulselength = 0;
    }
  }
if (digitalRead(servo0up) == HIGH);

Adding a semicolon to the end of an if statement means that the only code executed if the condition evaluates to true is the semicolon.

I'm using the PWM shield because I need the servos to start off slow, run at full speed, and then slow down again.

You can do that with the standard servo library and no shield if you want to.

It .... doesn't respond to my switches.

Why would it ? I am not familiar with the servo driver but doesn't it need to be told that the pulse length has been changed ?

Basic two button servo code that should work with your toggle switch.

//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}