vittascience:labyrinthe
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 | ||
| vittascience:labyrinthe [2026/03/06 16:18] – [algorythme essai] admin | vittascience:labyrinthe [2026/03/06 16:23] (Version actuelle) – [algorythme essai] admin | ||
|---|---|---|---|
| Ligne 65: | Ligne 65: | ||
| * 8- tourner encore de 180° ( 2 fois tourner droite) | * 8- tourner encore de 180° ( 2 fois tourner droite) | ||
| * 8- si distance > 20 => avancer | * 8- si distance > 20 => avancer | ||
| + | |||
| + | |||
| + | {{ : | ||
| {{ : | {{ : | ||
| + | |||
| + | <code c laby0033.ino> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | MeDCMotor motor_L(9); | ||
| + | MeDCMotor motor_R(10); | ||
| + | // Ultrasonic on PORT_3 | ||
| + | MeUltrasonicSensor ultrasonic_3(PORT_3); | ||
| + | |||
| + | int distancemax; | ||
| + | int pause; | ||
| + | int vitesse; | ||
| + | |||
| + | void mBot_setMotorLeft(int8_t dir, int16_t speed) { | ||
| + | speed = speed/ | ||
| + | motor_L.run((9) == M1 ? -(dir*speed) : (dir*speed)); | ||
| + | } | ||
| + | |||
| + | void mBot_setMotorRight(int8_t dir, int16_t speed) { | ||
| + | speed = speed/ | ||
| + | motor_R.run((10) == M1 ? -(dir*speed) : (dir*speed)); | ||
| + | } | ||
| + | |||
| + | void avancer() { | ||
| + | while (ultrasonic_3.distanceCm() >= distancemax) { | ||
| + | mBot_setMotorRight(1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | } | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | delay(1000*pause); | ||
| + | } | ||
| + | |||
| + | void droite() { | ||
| + | mBot_setMotorRight(-1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | delay(1000*pause); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | void gauche() { | ||
| + | mBot_setMotorLeft(-1, | ||
| + | mBot_setMotorRight(1, | ||
| + | delay(1000*pause); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | |||
| + | void setup() { | ||
| + | distancemax = 3; | ||
| + | pause = 1; | ||
| + | vitesse = 22; | ||
| + | avancer(); | ||
| + | droite(); | ||
| + | avancer(); | ||
| + | gauche(); | ||
| + | avancer(); | ||
| + | gauche(); | ||
| + | avancer(); | ||
| + | droite(); | ||
| + | mBot_setMotorRight(1, | ||
| + | mBot_setMotorLeft(1, | ||
| + | delay(1000*1); | ||
| + | mBot_setMotorRight(0, | ||
| + | mBot_setMotorLeft(0, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | } | ||
| + | </ | ||
/home/chanteri/www/fablab37110/data/attic/vittascience/labyrinthe.1772810280.txt.gz · Dernière modification : de admin
