Arduino R3 / & Adafruit 16 Channel Servo Shield

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

Picture of Arduino board I am using.

You will have to give a better description of what you want to achieve.

To get something random, look at the random() function.
To get something that looks like it is doing things at the same time, use a millis() based approach as demonstrated in e.g. Demonstration code for several things at the same time

The shield uses I2C for communication with the Arduino so the functions like pinMode, analogWrite etc will have no effect.

sterretje:
You will have to give a better description of what you want to achieve.

To get something random, look at the random() function.
To get something that looks like it is doing things at the same time, use a millis() based approach as demonstrated in e.g. Demonstration code for several things at the same time

The shield uses I2C for communication with the Arduino so the functions like pinMode, analogWrite etc will have no effect.

Thanks for replying sterretje. I want the servos to sweep randomly between 0 & 180 degrees, all at different times...at this point I do not think even random() will work... The shield uses PWM language only (from what I can gather)

What I can do is sweep them all at the same time.

Here is a link to exactly what I want to achieve, just using the adafruit 16 channel servo shield....

I'm going to scrap the shield, and go with just the arduino board and jumper wires.