Advertisement
Guest User

Tekenrobot_Lianne

a guest
Sep 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <Ultrasonic.h>
  2. Ultrasonic ultrasonic(7);
  3.  
  4. #include <SparkFunMiniMoto.h>
  5. MiniMoto motor0(0xC4);
  6. MiniMoto motor1(0xC0);
  7. #define FAULTn 16
  8. #define startKnop 2
  9. #define anglePin A2
  10. #define ledPin 13
  11. #define afstandsmeter 7
  12.  
  13. int snelheid = 20;
  14. int bocht = 0;
  15. int snelheidMotor1 = 0;
  16. int snelheidMotor2 = 0;
  17. int RangeInCentimeters = 0;
  18.  
  19. boolean aan = false;
  20.  
  21. void setup()
  22. {
  23. pinMode(FAULTn, INPUT);
  24. pinMode(startKnop, INPUT);
  25. pinMode(anglePin, INPUT);
  26. pinMode(ledPin, OUTPUT);
  27. pinMode(afstandsmeter, INPUT);
  28. Serial.begin(9600);
  29. }
  30.  
  31. void loop() {
  32. if (digitalRead(startKnop) == HIGH) {
  33. if (aan == false) {
  34. aan = true;
  35. } else {
  36. aan = false;
  37. }
  38. delay(250);
  39. }
  40. }
  41.  
  42. bocht = analogRead(anglePin);
  43.  
  44. if (bocht > 823) {
  45. snelheidMotor1 = 0;
  46. }
  47. if (bocht < 200) {
  48. snelheidMotor2 = 0;
  49. }
  50.  
  51.  
  52. motor0.drive(snelheidMotor1);
  53. motor1.drive(snelheidMotor2);
  54.  
  55.  
  56. if (aan == true) {
  57. digitalWrite(ledPin, HIGH);
  58. motor0.drive(20);
  59. motor1.drive(20);}
  60.  
  61. else {
  62. digitalWrite(ledPin, LOW);
  63. motor0.stop();
  64. motor1.stop(); }
  65.  
  66.  
  67.  
  68. if (RangeInCentimeters < 10) {
  69. if (random(0, 2) == 0) {
  70. snelheidMotor1 = 0;
  71. snelheidMotor2 = 40;
  72. delay(500);
  73. }
  74. }
  75.  
  76. else {
  77. snelheidMotor1 = 40;
  78. snelheidMotor2 = 0;
  79. delay(500);
  80. }
  81.  
  82. {
  83. snelheidMotor1 = 40;
  84. snelheidMotor2 = 40;
  85. }
  86.  
  87. {
  88. motor0.drive(snelheidMotor1);
  89. motor1.drive(snelheidMotor2);
  90. }
  91.  
  92.  
  93. {
  94. digitalWrite(ledPin, LOW);
  95. motor0.stop();
  96. motor1.stop();
  97. }
  98.  
  99. {
  100. RangeInCentimeters = ultrasonic.MeasureInCentimeters ();
  101. Serial.print(RangeInCentimeters);
  102. Serial.println(" cm");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement