SHARE
TWEET

Untitled

a guest Nov 15th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int getDistanza(){
  2.     int distanza;
  3.   unsigned long tempo;
  4.  
  5.     digitalWrite(TRIG_PIN, HIGH);
  6.     delayMicroseconds(10);
  7.     digitalWrite(TRIG_PIN, LOW);
  8.  
  9.     tempo = pulseIn(ECHO_PIN, HIGH);
  10.     distanza = (0.033765 * tempo/2);
  11.     delayMicroseconds(10);
  12.  
  13.   return distanza;
  14. }
  15.  
  16.  
  17.  
  18.   int distanza;
  19.  
  20.   for(int i=0; i<10; i++){
  21.     distanza += getDistanza();
  22.   }
  23.  
  24.   distanza = distanza/10;
  25.   Serial.println("Distanza: " + String(distanza) + "cm");
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