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 11:33] – [Contacts] 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 330: | Ligne 334: | ||
servoLeft.write(135); | servoLeft.write(135); | ||
servoRight.write(135); | servoRight.write(135); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Avec le bluetooth (message provenant du robot): | ||
+ | < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | Servo servoLeft; | ||
+ | Servo servoRight; | ||
+ | |||
+ | NewPing sonar(7, 6, 200); | ||
+ | |||
+ | SoftwareSerial BTSerial(4, 8); // TX, RX | ||
+ | |||
+ | void setup() { | ||
+ | servoLeft.attach(11); | ||
+ | servoRight.attach(10); | ||
+ | // | ||
+ | BTSerial.begin(9600); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | gestionSonar(); | ||
+ | } | ||
+ | |||
+ | void gestionSonar() { | ||
+ | int distance = sonar.ping_cm(); | ||
+ | avancer(); | ||
+ | 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 && 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(" | ||
} | } | ||
projets/2019/stageavrilubo.1555580012.txt.gz · Dernière modification : 2024/04/16 22:27 (modification externe)