Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int getDistanza(){
- int distanza;
- unsigned long tempo;
- digitalWrite(TRIG_PIN, HIGH);
- delayMicroseconds(10);
- digitalWrite(TRIG_PIN, LOW);
- tempo = pulseIn(ECHO_PIN, HIGH);
- distanza = (0.033765 * tempo/2);
- delayMicroseconds(10);
- return distanza;
- }
- int distanza;
- for(int i=0; i<10; i++){
- distanza += getDistanza();
- }
- distanza = distanza/10;
- Serial.println("Distanza: " + String(distanza) + "cm");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement