projets:2019:stageavrilubo
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| projets:2019:stageavrilubo [2019/04/18 14:19] – christian.jacolot | projets:2019:stageavrilubo [2024/04/16 22:26] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 235: | Ligne 235: | ||
| </ | </ | ||
| + | |||
| + | Android APK pour le robot Arduino: | ||
| + | https:// | ||
| + | |||
| Ligne 335: | Ligne 339: | ||
| - | Avec le bluetooth | + | Avec le bluetooth |
| < | < | ||
| #include < | #include < | ||
| Ligne 362: | Ligne 366: | ||
| int distance = sonar.ping_cm(); | int distance = sonar.ping_cm(); | ||
| avancer(); | avancer(); | ||
| - | if (distance < 10) { | + | if (distance > 0 && distance < 10) { |
| + | BTSerial.println(" | ||
| + | reculer(); | ||
| + | tournerGauche(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void stop() { | ||
| + | servoLeft.write(90); | ||
| + | servoRight.write(90); | ||
| + | BTSerial.println(" | ||
| + | } | ||
| + | |||
| + | void avancer() { | ||
| + | servoLeft.write( 0 ); // 0 => sens, 180 => autre sens | ||
| + | servoRight.write( 180 ); // | ||
| + | BTSerial.println(" | ||
| + | } | ||
| + | |||
| + | void reculer() { | ||
| + | servoLeft.write( 180 ); // 0 => sens, 180 => autre sens | ||
| + | servoRight.write( 0 ); // | ||
| + | BTSerial.println(" | ||
| + | } | ||
| + | |||
| + | void tournerGauche() { | ||
| + | servoLeft.write(45); | ||
| + | servoRight.write(45); | ||
| + | BTSerial.println(" | ||
| + | } | ||
| + | |||
| + | void tournerDroite() { | ||
| + | servoLeft.write(135); | ||
| + | servoRight.write(135); | ||
| + | BTSerial.println(" | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | Avec le bluetooth (piloter le robot): | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | Servo servoLeft; | ||
| + | Servo servoRight; | ||
| + | |||
| + | NewPing sonar(7, 6, 200); | ||
| + | |||
| + | SoftwareSerial BTSerial(4, 8); // TX, RX | ||
| + | |||
| + | String message; | ||
| + | |||
| + | void setup() { | ||
| + | servoLeft.attach(11); | ||
| + | servoRight.attach(10); | ||
| + | // | ||
| + | BTSerial.begin(9600); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | gestionSonar(); | ||
| + | readBTSerial(); | ||
| + | } | ||
| + | |||
| + | String readBTSerial() { | ||
| + | while (BTSerial.available()) { | ||
| + | message = BTSerial.readString(); | ||
| + | } | ||
| + | if (message == " | ||
| + | avancer(); | ||
| + | } else if (message == " | ||
| + | reculer(); | ||
| + | } else if (message == " | ||
| + | tournerGauche(); | ||
| + | } else if (message == " | ||
| + | tournerDroite(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void gestionSonar() { | ||
| + | int distance = sonar.ping_cm(); | ||
| + | avancer(); | ||
| + | if (distance > 0 && | ||
| BTSerial.println(" | BTSerial.println(" | ||
| reculer(); | reculer(); | ||
projets/2019/stageavrilubo.1555589988.txt.gz · Dernière modification : 2024/04/16 22:27 (modification externe)
