It looks like the answer is no but thought I'd ask. I'm using the basic Servo.h library, so this question may be moot when the PCA9685 driver arrives, it uses an entirely different library, but learning more about these as I go.
Think of the joints in a skeleton. I would like to name them backbone, shoulder, elbow, etc. This way I can easily identify mods I need to make to each servo's properties (speed, direction, etc.) on the fly. I'm aware the easiest way would be to just use arrays, but I'm hoping I don't have to fiddle about mapping which index is the shoulder, which is elbow, etc.
My hope is to be able to do something like moveServo(backbone, 0, 180, 10) where 0 is start, 180 is end, 10 is speed. I'll need to be able to dynamically change these on the fly.
This is not working code but my muddled thinking-through of setting up the structures for easier access. The first version just uses a string for "name" (and obviously doesn't work)
typedef struct {
String servo_name;
char pin_num;
int speed;
} servo_props;
/* object name, pin number, speed in MS*/
servo_props props[] = {
{ "backbone", 9, 15 },
{ "shoulder", 10, 15},
{ "elbow", 11, 15 }
};
I suppose this would do if it's the only way, but I can't find anything on the typedef for Servo objects.
Servo backbone;
Servo shoulder;
Servo elbow;
typedef struct {
[typedef?] servo_object; // What typedef to use here? Couldn't figure it out.
char pin_num;
int speed;
} servo_props;
/* object name, pin number, speed in MS*/
servo_props props[] = {
{ backbone, 9, 15 },
{ shoulder, 10, 15},
{ elbow, 11, 15 }
};
I've read up on pointers and object references, don't seem like they'd work for what I'm trying to do.
What's a good way to approach this, should I just stop trying to be smarter than I am and use arrays? ![]()