Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <NewPing.h>
  2. #include <Servo.h>  
  3. /* **************************************************************** */
  4. Servo myservo;                  
  5. NewPing metr(trig_pin, echo_pin, max_distance);
  6. /* **************************************************************** */
  7. int posit = 0;
  8. int echo_pin = 40;
  9. int trig_pin = 50;
  10. int max_distance = 300;
  11. float distance;
  12. /* **************************************************************** */
  13.  
  14. void setup()
  15. {
  16.   Serial.begin(9600);
  17.   myservo.attach(30);
  18.   pinMode(echo_pin, INPUT);
  19.   pinMode(trig_pin, OUTPUT);
  20. }
  21. /* **************************************************************** */
  22. void loop()
  23. {  
  24.   for(posit = 0; posit <= 180; posit += 1) {
  25.     myservo.write(posit);
  26.     meter();
  27.     delay(25);
  28.   }
  29.  
  30.   for(posit = 180; posit >= 0; posit -= 1) {                                
  31.     myservo.write(posit);
  32.     meter();
  33.     delay(25);
  34.   }
  35. }
  36. /* **************************************************************** */
  37. void meter(){
  38.     distance = metr.ping_cm();      // uloží do proměnné vzdálenost výsledek ping_cm (co měří vzdálenost)
  39.     Serial.println(distance);
  40.     delay(20);  
  41.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement