abdullahkahraman

Untitled

Apr 15th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 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. void front_motor_turn_left()
  12. {
  13. digitalWrite(front_motor_low, HIGH);
  14. digitalWrite(front_motor_high, LOW);
  15. digitalWrite(front_motor_enable, HIGH);
  16. }
  17.  
  18. void front_motor_turn_right()
  19. {
  20. digitalWrite(front_motor_low, LOW);
  21. digitalWrite(front_motor_high, HIGH);
  22. digitalWrite(front_motor_enable, HIGH);
  23. }
  24.  
  25. void front_motor_turn_off()
  26. {
  27. digitalWrite(front_motor_enable, LOW);
  28. }
  29.  
  30. void back_motor_run()
  31. {
  32. digitalWrite(back_motor_enable, HIGH);
  33. }
  34.  
  35. void back_motor_stop()
  36. {
  37. digitalWrite(back_motor_enable, LOW);
  38. }
  39.  
  40.  
  41. void setup() {
  42. pinMode(IR_sensor_IS471F_pin, INPUT);
  43. pinMode(back_motor_low, OUTPUT);
  44. pinMode(back_motor_high, OUTPUT);
  45. pinMode(back_motor_enable, OUTPUT);
  46. pinMode(front_motor_low, OUTPUT);
  47. pinMode(front_motor_high, OUTPUT);
  48. pinMode(front_motor_enable, OUTPUT);
  49.  
  50. digitalWrite(back_motor_low, HIGH);
  51. digitalWrite(back_motor_high, LOW);
  52. digitalWrite(back_motor_enable, LOW);
  53. digitalWrite(front_motor_low, HIGH);
  54. digitalWrite(front_motor_high, LOW);
  55. digitalWrite(front_motor_enable, LOW);
  56. }
  57.  
  58.  
  59. void loop() {
  60. sensor_status = digitalRead(IR_sensor_IS471F_pin);
  61.  
  62. back_motor_run();
  63.  
  64. if (sensor_status == HIGH)
  65. {
  66. front_motor_turn_left();
  67. }
  68. else
  69. {
  70. front_motor_turn_right();
  71. }
  72. }
Add Comment
Please, Sign In to add comment