Advertisement
abdullahkahraman

Untitled

Apr 15th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. int back_motor_low = 8;
  2. int back_motor_high = 9;
  3. int back_motor_enable = 10;
  4. int front_motor_low = 13;
  5. int front_motor_high = 12;
  6. int front_motor_enable = 11;
  7.  
  8. int IR_sensor_IS471F_pin = 2;
  9. int sensor_status = 0;
  10.  
  11. int timeout = 0;
  12. int toggler = 0;
  13.  
  14. void front_motor_turn_left()
  15. {
  16. digitalWrite(front_motor_low, HIGH);
  17. digitalWrite(front_motor_high, LOW);
  18. digitalWrite(front_motor_enable, HIGH);
  19. }
  20.  
  21. void front_motor_turn_right()
  22. {
  23. digitalWrite(front_motor_low, LOW);
  24. digitalWrite(front_motor_high, HIGH);
  25. digitalWrite(front_motor_enable, HIGH);
  26. }
  27.  
  28. void front_motor_turn_off()
  29. {
  30. digitalWrite(front_motor_enable, LOW);
  31. }
  32.  
  33. void back_motor_run()
  34. {
  35. digitalWrite(back_motor_enable, HIGH);
  36. }
  37.  
  38. void back_motor_stop()
  39. {
  40. digitalWrite(back_motor_enable, LOW);
  41. }
  42.  
  43.  
  44. void setup() {
  45. pinMode(IR_sensor_IS471F_pin, INPUT);
  46. pinMode(back_motor_low, OUTPUT);
  47. pinMode(back_motor_high, OUTPUT);
  48. pinMode(back_motor_enable, OUTPUT);
  49. pinMode(front_motor_low, OUTPUT);
  50. pinMode(front_motor_high, OUTPUT);
  51. pinMode(front_motor_enable, OUTPUT);
  52.  
  53. digitalWrite(back_motor_low, HIGH);
  54. digitalWrite(back_motor_high, LOW);
  55. digitalWrite(back_motor_enable, LOW);
  56. digitalWrite(front_motor_low, HIGH);
  57. digitalWrite(front_motor_high, LOW);
  58. digitalWrite(front_motor_enable, LOW);
  59. }
  60.  
  61.  
  62. void loop() {
  63. sensor_status = digitalRead(IR_sensor_IS471F_pin);
  64.  
  65. if(toggler == 0)
  66. {
  67. toggler = 1;
  68. back_motor_run();
  69. }
  70. else
  71. {
  72. back_motor_stop();
  73. toggler = 0;
  74. }
  75.  
  76. if (sensor_status == HIGH)
  77. {
  78. front_motor_turn_left();
  79. timeout++;
  80. }
  81. else
  82. {
  83. front_motor_turn_right();
  84. }
  85.  
  86. delay(10);
  87.  
  88. if(timeout > 300)
  89. {
  90. //back_motor_stop();
  91.  
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement