SHARE
TWEET

Untitled

a guest Jan 22nd, 2017 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <Servo.h>
  3. #define trigPin 7
  4. #define echoPin 6
  5. Servo myservo;
  6.  
  7. int val;
  8.  
  9. void setup()
  10. {
  11.   myservo.attach(9);
  12.   Serial.begin (9600);
  13.   pinMode(trigPin, OUTPUT);
  14.   pinMode(echoPin, INPUT);
  15. }
  16.  
  17. void loop()
  18. {
  19.   long duration, distance;
  20.   digitalWrite(trigPin, LOW);
  21.   delayMicroseconds(2);
  22.   digitalWrite(trigPin, HIGH);
  23.   delayMicroseconds(10);
  24.   digitalWrite(trigPin, LOW);
  25.   duration = pulseIn(echoPin, HIGH);
  26.   distance = (duration/2) / 29.1;
  27.   if (distance > 40 or distance == 0){
  28.     Serial.println("te ver");  
  29.     delay(400); }
  30.   else{
  31.     myservo.write(distance * 5);                  
  32.     delay(400);                          
  33.     Serial.println(distance);
  34.   }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top