#include "Grove_Motor_Driver_TB6612FNG.
h"
#include <Wire.h>
MotorDriver motor;
// Capteurs
const int C1 = A0; // Gauche
const int C2 = A1; // Centre
const int C3 = A2; // Droit
// Bouton poussoir
const int bouton = 2;
void setup() {
[Link]();
[Link]();
pinMode(C1, INPUT);
pinMode(C2, INPUT);
pinMode(C3, INPUT);
pinMode(bouton, INPUT_PULLUP); // Bouton actif à LOW
}
void loop() {
// En attente du bouton
if (digitalRead(bouton) == HIGH) {
[Link](MOTOR_CHA);
[Link](MOTOR_CHB);
return;
}
int capteurGauche = digitalRead(C1);
int capteurCentre = digitalRead(C2);
int capteurDroit = digitalRead(C3);
if (capteurCentre == 1 && capteurGauche == 0 && capteurDroit == 0) {
avancer();
}
else if (capteurGauche == 1) {
tournerGauche();
}
else if (capteurDroit == 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);
}