#include "Grove_Motor_Driver_TB6612FNG.
h"
#include <Wire.h>
MotorDriver motor;
// Capteurs
const int capteurGauche = A0;
const int capteurCentre = A1;
const int capteurDroit = A2;
// Bouton
const int bouton = 2;
void setup() {
[Link]();
[Link]();
pinMode(capteurGauche, INPUT);
pinMode(capteurCentre, INPUT);
pinMode(capteurDroit, INPUT);
pinMode(bouton, INPUT_PULLUP); // Bouton actif à LOW
}
void loop() {
// Attend que l'utilisateur appuie sur le bouton
if (digitalRead(bouton) == HIGH) {
[Link](MOTOR_CHA);
[Link](MOTOR_CHB);
return;
}
int G = digitalRead(capteurGauche);
int C = digitalRead(capteurCentre);
int D = digitalRead(capteurDroit);
if (C == 1 && G == 0 && D == 0) {
avancer();
}
else if (G == 1) {
tournerGauche();
}
else if (D == 1) {
tournerDroite();
}
else {
arreter();
}
}
void avancer() {
[Link](MOTOR_CHA, 200);
[Link](MOTOR_CHB, 200);
}
void tournerGauche() {
[Link](MOTOR_CHA, 100);
[Link](MOTOR_CHB, 200);
}
void tournerDroite() {
[Link](MOTOR_CHA, 200);
[Link](MOTOR_CHB, 100);
}
void arreter() {
[Link](MOTOR_CHA);
[Link](MOTOR_CHB);
}