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;
}
}