Hello all,
I need help with a project I am working on to get servos to rotate lots of fake eyes inside of a pumpkin. The code I am using is for the Adafruit 16-channel PWM & Servo driver. I have code that works fine with just the arduino, but I thought a shield might make this a more permanent build
My code that I have works just not quite how I want it too. I need help tweaking it to rotate my servos at random. I have attached my code below as well as a link to a short clip of my setup.
Some other thoughts:
Can this be achieved easily? Or should I just buy some Y cables and use a breadboard with just the Arduino?
Will analogWrite(), analogRead, digitalRead(), digitaleWrite(), and pinMode() help with communicating to arduino?
Any help and advice is greatly appreciated, Thanks for you time in advance
-Mike
Setup Link Just a short clip.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define DEFAULT_PULSE_WIDTH 1500
#define FREQUENCY 50 // 20 millisecond (50 hz) PWM Period
void setup() {
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
}
void loop() { //Set servo port numbers and commands for direction of movement.
pwm.setPWM(0, 0, pulseWidth(120)); //Create a command for each servo motor
pwm.setPWM(1, 0, pulseWidth(140));
delay(5000);
pwm.setPWM(0, 0, pulseWidth(30)); //Create a command for each servo motor
pwm.setPWM(1, 0, pulseWidth(55));
delay(5000);
}
int pulseWidth (int angle)
{
int pulse_wide, analog_value;
pulse_wide =(map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH));
analog_value = int (float (pulse_wide) / 1000000 * FREQUENCY * 4096);
return analog_value;
}