Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #define Naped_PP
  2. #define Naped_PT
  3. #define Naped_LP
  4. #define Naped_PT
  5.  
  6. #define trigPin
  7. #define echoPin
  8.  
  9. #define vacuum
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. void setup() {
  17.  
  18. pinMode(Naped_PP, OUTPUT);
  19. pinMode(Naped_LP, OUTPUT);
  20. pinMode(Naped_PT, OUTPUT);
  21. pinMode(Naped_LT, OUTPUT);
  22.  
  23. pinMode(trigPin,OUTPUT);
  24. pinMode(echoPin,INPUT);
  25.  
  26. pinMode(vacuum, OUTPUT);
  27. }
  28.  
  29.  
  30. long distance;
  31.  
  32. void loop() {
  33.  
  34. digitalWrite(vacuum, HIGH);
  35. distance = pomiarOdleglosci();
  36. jazda(distance);
  37. }
  38.  
  39.  
  40.  
  41. int pomiarOdleglosci(){
  42.  
  43. long duration
  44.  
  45. //pomiar odleglosci
  46. digitalWrite(trigPin,LOW);
  47. delayMicroseconds(2);
  48. digitalWrite(trigPin,LOW);
  49. delayMicroseconds(10);
  50. digitalWrite(trigPin,LOW);
  51.  
  52. //odczyt pomiaru
  53. duration = pulseIn(echoPin, HIGH);
  54.  
  55. return duration/58;
  56. }
  57.  
  58. void jazda( int distance) {
  59. if(distance < 15){
  60. digitalWrite(Naped_PP, LOW);
  61. digitalWrite(Naped_PT, HIGH);
  62. digitalWrite(Naped_LP, HIGH);
  63. digitalWrite(Naped_LT, LOW);
  64. }
  65. else{
  66. digitalWrite(Naped_PP, HIGH);
  67. digitalWrite(Naped_PT, LOW);
  68. digitalWrite(Naped_LP, HIGH);
  69. digitalWrite(Naped_LT, LOW);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement