Étape 6: CODE!!!
La très première chose, vous voulez faire est de s’assurer que votre bouclier ou xbee est débranché de l’arduino. Ou vérifiez que les cavaliers corrects sont au bon endroit (dans mon cas). J’ai écrit ce code et si vous l’utilisez que voulez crédit.
C’est le code pour l’envoi Arduino : void setup() void loop() int FingerV1 = analogRead(Finger1); if (FingerV1 < 200) FingerV1 = 200; byte servoVal1 = map(FingerV1,460, 200, 255, 0); Serial.print(servoVal1); delay(100); Here is the receiving: #include Servo myservo1; // create servo object to control a servo void setup() myservo1.attach(2); // attaches the servo on pin 9 to the servo object void loop() // Send the servo to the position read... (note: you get to make this happen)
int Finger1 = 0;
int Finger2 = 1;
int Finger3 = 2;
int Finger4 = 3;
int Finger5 = 4;
{
Serial.begin(9600);
}
{
byte servoValue1;
byte servoValue2;
byte servoValue3;
byte servoValue4;
byte servoValue5;
int FingerV2 = analogRead(Finger2);
int FingerV3 = analogRead(Finger3);
int FingerV4 = analogRead(Finger4);
int FingerV5 = analogRead(Finger5);
else if (FingerV1 > 460) FingerV1 = 460;
if (FingerV2 < 200) FingerV2 = 200;
else if (FingerV2 > 460) FingerV2 = 460;
if (FingerV3 < 200) FingerV3 = 200;
else if (FingerV3 > 460) FingerV3 = 460;
if (FingerV4 < 200) FingerV4 = 200;
else if (FingerV4 > 460) FingerV4 = 460;
if (FingerV5 < 200) FingerV5 = 200;
else if (FingerV5 > 460) FingerV5 = 460;
byte servoVal2 = map(FingerV2,460, 200, 255, 0);
byte servoVal3 = map(FingerV3,460, 200, 255, 0);
byte servoVal4 = map(FingerV4,460, 200, 255, 0);
byte servoVal5 = map(FingerV5,460, 200, 255, 0);
Serial.print(servoVal2);
Serial.print(servoVal3);
Serial.print(servoVal4);
Serial.print(servoVal5);
}
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
{
Serial.begin(9600);
myservo2.attach(3);
myservo3.attach(4);
myservo4.attach(5);
myservo5.attach(6);
}
{
if(Serial.available() >=5)
{
byte servoAng1 = Serial.read();
byte servoAng2 = Serial.read();
byte servoAng3 = Serial.read();
byte servoAng4 = Serial.read();
byte servoAng5 = Serial.read();
myservo1.write(servoAng1);
myservo2.write(servoAng2);
myservo3.write(servoAng3);
myservo4.write(servoAng4);
myservo5.write(servoAng5);
}
}