Ok, so I found a new approach to my problem. I'm a bit more hopeful but I can't get it to compile.
Here is what I found (the list of compiler errors is huge):
//(this sketch is straight from the playground)
// test sketch for MegaServo library
// this will sweep all servos back and forth once, then position according to voltage on potPin
#include <MegaServo.h>
#define FIRST_SERVO_PIN 22
MegaServo Servos[MAX_SERVOS] ; // max servos is 32 for mega, 8 for other boards
int pos = 0; // variable to store the servo position
int potPin = 0; // connect a pot to this pin.
void setup()
{
for( int i =0; i < MAX_SERVOS; i++)
Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);
sweep(0,180,2); // sweep once
}
void sweep(int min, int max, int step)
{
for(pos = min; pos < max; pos += step) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
for( int i =0; i < MAX_SERVOS; i++){
Servos[i].write( pos); // tell servo to go to position
}
delay(15); // waits 15ms for the servo to move
}
for(pos = max; pos>=min; pos-=step) // goes from 180 degrees to 0 degrees
{
for( int i =0; i < MAX_SERVOS; i++){
Servos[i].write( pos); // tell servo to go to position
}
delay(15); // waits 15ms for the servo to move
}
}
void loop()
{
pos = analogRead(potPin); // read a value from 0 to 1023
for( int i =0; i < MAX_SERVOS; i++)
Servos[i].write( map(pos, 0,1023,0,180));
delay(15);
}
I compared the above sketch to others I found (sorry they aren't cited, I didn't record where the other similar examples were from) and here are the changes I made:
#include <MegaServo.h>
#include <Wire.h>
#include <arduino.h>
#define NBR_SERVOS 12
#define FIRST_SERVO_PIN 2
MegaServo Servos[NBR_SERVOS] ; // max servos is 12
MegaServo MegaServo;
int pos = 0; // variable to store the servo position
int potPin = 0; // connect a pot to this pin.
void setup()
{
Serial.begin(9600);
MegaServo.writeMicroseconds(1500);
int i = 0;
pinMode(i,OUTPUT);
}
void Servos digitalWrite.MegaServo( )
{
for( int i =0; i < NBR_SERVOS; i++)
Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);
sweep(0,180,2); // sweep once
}
void sweep(int min, int max, int step)
{
for(pos = min; pos < max; pos += step) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
for( int i =0; i < NBR_SERVOS; i++){
Servos[i].write( pos); // tell servo to go to position
}
delay(15); // waits 15ms for the servo to move
}
for(pos = max; pos>=min; pos-=step) // goes from 180 degrees to 0 degrees
{
for( int i =0; i < NBR_SERVOS; i++){
Servos[i].write( pos); // tell servo to go to position
}
delay(15); // waits 15ms for the servo to move
}
}
void loop()
{
pos = analogRead(potPin); // read a value from 0 to 1023
for( int i =0; i < NBR_SERVOS; i++)
Servos[i].write( map(pos, 0,1023,0,180));
delay(15);
}
compiler error: MegaServo:23: error: expected initializer before 'digitalWrite'
This is the only error that this version produces. I don't know that it's necessarily a good thing or not. I guess I don't understand what an 'expected initializer' is, even after some research on it. If this does end up compiling, I don't know that it will work correctly as I don't understand most of what is going on in it. Please don't ask me WHY I made some of the changes were made in it as I don't really remember and probably couldn't tell you in the first place. All I know is that this is the closest it has come to compiling.
Thanx for any input on this