Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
wiki:ateliers:arduino:1 [2018/02/21 14:57] antoinem |
wiki:ateliers:arduino:1 [2018/02/21 15:35] (Version actuelle) antoinem |
||
---|---|---|---|
Ligne 15: | Ligne 15: | ||
1*Breadboard | 1*Breadboard | ||
- | La structure du bras : | + | La structure du bras que j' |
- | + | ||
+ | Vous pouvez refaire le votre à condition de ne pas dépasser le couple max de vos servos. | ||
===== Le montage ===== | ===== Le montage ===== | ||
Ligne 24: | Ligne 23: | ||
Nous ne pouvons pas alimenter les servomoteurs en les branchant à la sortie 5V de l' | Nous ne pouvons pas alimenter les servomoteurs en les branchant à la sortie 5V de l' | ||
N' | N' | ||
+ | |||
+ | ===== Code ===== | ||
+ | |||
+ | Voici un code pour tester votre montage : | ||
+ | |||
+ | < | ||
+ | /* Code inspiré de celui proposé par le blog ElectroniqueEnAmateur */ | ||
+ | |||
+ | #include < | ||
+ | |||
+ | |||
+ | Servo myservo1, myservo2;// | ||
+ | String readString, servo1Str, servo2Str; | ||
+ | int posCible1, posCible2; //PosCiblei sera la position ciblée par le servomoteur (de 0° à 180°) | ||
+ | |||
+ | | ||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | myservo1.attach(9); | ||
+ | myservo2.attach(10); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | boolean fini = false ;//variable servant à savoir si nos servos ont fini le mouvement demandé | ||
+ | int pos1, pos2; | ||
+ | |||
+ | while (Serial.available()) //Boucle pour récupérer nos entrées claviers | ||
+ | { | ||
+ | delay(1); | ||
+ | if (Serial.available() > | ||
+ | { | ||
+ | char c = Serial.read(); | ||
+ | readString += c; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (readString.length() == 6) | ||
+ | { | ||
+ | |||
+ | servo1Str = readString.substring(0, | ||
+ | servo2Str = readString.substring(3, | ||
+ | | ||
+ | Serial.println(" | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(servo1Str); | ||
+ | Serial.print(" | ||
+ | Serial.print(servo2Str); | ||
+ | |||
+ | |||
+ | char carray1[5]; | ||
+ | servo1Str.toCharArray(carray1, | ||
+ | posCible1 = atoi(carray1); | ||
+ | |||
+ | char carray2[5]; | ||
+ | servo2Str.toCharArray(carray2, | ||
+ | posCible2 = atoi(carray2); | ||
+ | |||
+ | |||
+ | while (!fini) | ||
+ | { | ||
+ | pos1 = myservo1.read();// | ||
+ | pos2 = myservo2.read(); | ||
+ | |||
+ | |||
+ | if (pos1 < posCible1){ | ||
+ | myservo1.write(pos1 + 1);// | ||
+ | } | ||
+ | if (pos1 > posCible1){ | ||
+ | myservo1.write(pos1 - 1); | ||
+ | } | ||
+ | |||
+ | if (pos2 < posCible2){ | ||
+ | myservo2.write(pos2 + 1); | ||
+ | } | ||
+ | if (pos2 > posCible2){ | ||
+ | myservo2.write(pos2 - 1); | ||
+ | } | ||
+ | |||
+ | |||
+ | fini = ((pos1 == posCible1) && (pos2 == posCible2)); | ||
+ | |||
+ | delay(15); // pour limiter la vitesse | ||
+ | } | ||
+ | | ||
+ | | ||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | Serial.print(myservo1.read()); | ||
+ | Serial.print(" | ||
+ | Serial.print(myservo2.read()); | ||
+ | | ||
+ | readString=""; | ||
+ | } | ||
+ | } | ||
+ | </ | ||