Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <Grove_I2C_Motor_Driver.h>
  2. // default I2C address is 0x0f
  3. #define I2C_ADDRESS 0x0f
  4.  
  5. const int capteurGauche = 2;//Capteur Gauche
  6. const int capteurCentre = 5;//Capteur Avant
  7. const int capteurDroit = 6;//Capteur Droit
  8. const int capteurMilieu = 3;//Capteur Milieu
  9.  
  10. bool etatCapteurGauche;
  11. bool etatCapteurCentre;
  12. bool etatCapteurDroit;
  13.  
  14. void setup() {
  15. // put your setup code here, to run once:
  16. Serial.begin(9600);
  17. pinMode(capteurGauche, INPUT);
  18. pinMode(capteurCentre, INPUT);
  19. pinMode(capteurDroit, INPUT);
  20. Motor.begin(I2C_ADDRESS);
  21. }
  22.  
  23. void loop() {
  24. // put your main code here, to run repeatedly:
  25. etatCapteurGauche = digitalRead(capteurGauche);
  26. etatCapteurCentre = digitalRead(capteurCentre);
  27. etatCapteurDroit = digitalRead(capteurDroit);
  28.  
  29. if(etatCapteurCentre) //Si le capteur du centre détecte du noir
  30. {
  31. if(!etatCapteurGauche && etatCapteurDroit){
  32. Motor.speed(MOTOR1, -50);
  33. // Set speed of MOTOR2, Anticlockwise
  34. Motor.speed(MOTOR2, 50);
  35. }
  36. else if(etatCapteurGauche && !etatCapteurDroit)
  37. {
  38. Motor.speed(MOTOR1, 50);
  39. // Set speed of MOTOR2, Anticlockwise
  40. Motor.speed(MOTOR2, -50);
  41. }
  42. else {
  43. Motor.speed(MOTOR1, 100);
  44. // Set speed of MOTOR2, Anticlockwise
  45. Motor.speed(MOTOR2, 100);
  46. }
  47. }
  48. else if(!etatCapteurCentre) //Si le capteur du centre détecte du blanc
  49. {
  50. if(!etatCapteurGauche && etatCapteurDroit)
  51. {
  52. Motor.speed(MOTOR1, -50);
  53. // Set speed of MOTOR2, Anticlockwise
  54. Motor.speed(MOTOR2, 50);
  55. }
  56. else if(etatCapteurGauche && !etatCapteurDroit)
  57. {
  58. Motor.speed(MOTOR1, 50);
  59. // Set speed of MOTOR2, Anticlockwise
  60. Motor.speed(MOTOR2, -50);
  61. }
  62. else {
  63. Motor.speed(MOTOR1, 85);
  64. Motor.speed(MOTOR2, -85);
  65. delay(1150);
  66. }
  67. }
  68. else {
  69. Motor.stop(MOTOR1);
  70. Motor.stop(MOTOR2);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement