Hi Guys,
I am making a anamatronic hand and I am wondering if this code will work. It is new condensed version and I wonder if it will work. There is a sending glove that sends the movement of my hand to a seperate ardino via xbees.
#define MAX_FINGER 5
typedef struct {
byte servoValue;
byte servoVal;
int iFinger;
} DEFAULT servo[MAX_FINGER];
const int ciDefault[] - {200, 460};
void setup()
{
Serial.begin(9600);
}
void init_default()
{
int i = 0;
for (i = 0; i < MAX_FINGER; i++) {
servo[i].iFinger = analogRead(i);
if (servo[i].iFinger < ciDefault[0]) servo[i].iFinger = ciDefault[0];
else if (servo[i].iFinger > ciDefault[1]) servo[i].iFinger = ciDefault[1];
servo[i].servoVal = map(servo[i].iFinger, 460, 200, 255, 0);
Serial.print(servo[i].servoVal;
}
}
void loop()
{
init_default();
delay(100);
}
That is the sending one
Here is the receiving:
// #include
// create servo object to control a servo
typedef struct {
Servo myservo;
byte servoAng;
}SERVO servo[MAX_FINGER];
void setup()
{
Serial.begin(9600);
int i = 0;
for (i = 0; i < MAX_FINGER; i++) {
servo[i].myservo.attach(i + 2);
}
}
void loop()
{
if(Serial.available() >=5)
{
int i = 0;
for (i = 0; i < MAX_FINGER; i++) {
servo[i].servoAng = Serial.read();
servo[i].myservo.write( servo[i].servoAng );
}
// Send the servo to the position read... (note: you get to make this happen)
}
}