Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <ArduinoRobot.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4.  
  5. int turnSpeed = 150;
  6. int forwardSpeed = 200;
  7.  
  8. void setup() {
  9.  
  10. Robot.begin();
  11. Robot.motorsWrite(forwardSpeed, forwardSpeed);
  12. }
  13.  
  14. void loop()
  15. {
  16. // Si détection mur face -> Tourne
  17. if (Robot.analogRead(TK2) < 15){
  18. Robot.motorsStop();
  19. // Définition du degrés cible
  20. int compassInit = Robot.compassRead();
  21. int compass = compassInit -90;
  22. if (compass <= 0){
  23. do {
  24. turnLeft(turnSpeed);
  25. delay(100);
  26. } while (Robot.compassRead() < compassInit);
  27. compass += 360;
  28. }
  29. do {
  30. turnLeft(turnSpeed);
  31. delay(100);
  32. } while (Robot.compassRead() > compass);
  33. Robot.motorsStop();
  34. }
  35. // Sinon on avance
  36. else {
  37. Robot.motorsWrite(forwardSpeed, forwardSpeed);
  38. }
  39. }
  40.  
  41. void turnLeft(int speed)
  42. {
  43. Robot.motorsWrite(-speed, speed);
  44. }
  45.  
  46. void turnRight(int speed)
  47. {
  48. Robot.motorsWrite(speed, -speed);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement