Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <Ultrasonic.h>
  2.  
  3.  
  4.  
  5.  
  6.  
  7. volatile float maxfrontdistance = 15.00;
  8. volatile float maxleftdistance = 10.00 , maxrightdistance = 10.00;
  9. volatile float leftdistance, frontdistance, rightdistance;
  10. bool Leftclear, Frontclear, Rightclear;
  11.  
  12. Ultrasonic USleft(3, 10);
  13. Ultrasonic USfront(6, 11);
  14. Ultrasonic USright(5, 9);
  15.  
  16. void setup(){
  17. Serial.begin(9600);
  18. }
  19.  
  20. void loop(){
  21. checkfrontdistance();
  22. checkleftdistance();
  23. checkrightdistance();
  24.  
  25. if(!Leftclear){
  26. Serial.print("Left not clear");
  27. }
  28.  
  29.  
  30.  
  31.  
  32. delay(2000);
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. void checkleftdistance() {
  40. Serial.print("Left:");
  41. leftdistance = USleft.distanceRead();
  42. if (leftdistance>maxleftdistance)
  43. (Leftclear = true);
  44. Serial.print(USleft.distanceRead());
  45. Serial.println("cm");
  46. }
  47.  
  48. void checkfrontdistance() {
  49. Serial.print("Front:");
  50. frontdistance = USfront.distanceRead();
  51. if (frontdistance>maxfrontdistance)
  52. (Frontclear = true);
  53. Serial.print(USfront.distanceRead());
  54. Serial.println("cm");
  55.  
  56.  
  57. }
  58.  
  59. void checkrightdistance() {
  60. Serial.print("Right:");
  61. rightdistance = USright.distanceRead();
  62. if (rightdistance>maxrightdistance)
  63. (Rightclear = true);
  64. Serial.print(USright.distanceRead());
  65. Serial.println("cm");
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement