Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. #define distanceForward A0
  2. #define distanceLeft A1
  3. #define distanceRight A2
  4. #define distanceRightAngle A3
  5. #define distanceLeftAngle A4
  6. #define distanceBack A5
  7. int talk = 2;
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. void setup(){
  15. Serial.begin(9600);
  16. pinMode(talk, OUTPUT);
  17. pinMode(distanceForward, INPUT);
  18. // / Ir distance sensor pin for input signal to arduino, Front Facing
  19. pinMode(distanceLeftAngle, INPUT);
  20. // / Ir distance sensor pin for input signal to arduino, Left Angle
  21. pinMode(distanceRightAngle, INPUT);
  22. // / Ir distance sensor pin for input signal to arduino, Right Angle
  23. pinMode(distanceLeft, INPUT);
  24. // / Ir distance sensor pin for input signal to arduino, Left
  25. pinMode(distanceRight, INPUT);
  26. // / Ir distance sensor pin for input signal to arduino, Right
  27. pinMode(distanceBack, INPUT);
  28. // / Ir distance sensor pin for input signal to arduino, back
  29.  
  30. }
  31.  
  32. void hall_roam(){
  33.  
  34. Serial.write("forward");
  35.  
  36. if (analogRead(distanceLeftAngle) < 30){
  37. Serial.write("right");
  38. if (analogRead(distanceLeftAngle) > 30){
  39. Serial.write("forward");
  40. }
  41.  
  42. if (analogRead(distanceRightAngle) < 30){
  43. Serial.write("left");
  44. if (analogRead(distanceRightAngle) < 30){
  45. Serial.write("forward");
  46. }
  47.  
  48. if (analogRead(distanceForward) < 60){
  49. Serial.write("stop");
  50. if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)){
  51. Serial.write("left");
  52. if (analogRead(distanceForward) > 60){
  53. Serial.write("stop");
  54. }
  55. }
  56. }
  57. if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) > 60)){
  58. Serial.write("left");
  59. if (analogRead(distanceForward) > 60){
  60. Serial.write("stop");
  61. }
  62. }
  63. if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) < 60)){
  64. Serial.write("left");
  65. if (analogRead(distanceForward) > 60){
  66. Serial.write("stop");
  67. }
  68. }
  69. if ((analogRead(distanceLeft) > 60) && (analogRead(distanceRight) < 60)){
  70. Serial.write("left");
  71. if (analogRead(distanceForward) > 60){
  72. Serial.write("stop");
  73. }
  74.  
  75. }
  76. if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) > 60)){
  77. Serial.write("right");
  78. if (analogRead(distanceForward) > 60){
  79. Serial.write("stop");
  80. }
  81.  
  82. }
  83.  
  84. else{
  85. Serial.write("forward");
  86. }
  87.  
  88. }
  89. void roam(){
  90. Serial.write("forward");
  91. if (analogRead(distanceForward) < 60){
  92. Serial.write("stop");
  93. Serial.write("left");
  94. if (analogRead(distanceForward) > 60){
  95. Serial.write("stop");
  96. Serial.write("forward");
  97. }
  98.  
  99. }
  100.  
  101. }
  102. void talkbb8(){
  103. pinMode(talk, HIGH);
  104. pinMode(talk, LOW);
  105. }
  106.  
  107.  
  108. void chill(){
  109. Serial.write("stop");
  110. talkbb8();
  111. }
  112. void loop(){
  113.  
  114. if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)){
  115. hall_roam();
  116. }
  117. else if ((analogRead(distanceForward) < 60) && (analogRead(distanceBack) < 60)){
  118. Serial.write("left");
  119. if ((analogRead(distanceLeft) < 60) && (analogRead(distanceRight) < 60)){
  120. Serial.write("stop");
  121. hall_roam();
  122. }
  123. }
  124.  
  125. else
  126. {
  127. roam();
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement