Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#define TRIGGER1 2
#define ECHO1 3
#define TRIGGER2 4
#define ECHO2 5
void setup() {
pinMode(TRIGGER1,OUTPUT);
pinMode(ECHO1,INPUT);
pinMode(TRIGGER2,OUTPUT);
pinMode(ECHO2,INPUT);
Serial.begin(9600);
}
float measure(int triggerPin, int echoPin) {
// trigger high for a short time and get duration
// of the high state on echo pin.
digitalWrite(triggerPin,HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin,LOW);
// Convert duration of high echo to centimeters.
return pulseIn(echoPin,HIGH) / 58.00;
}
void getAndLogMeasurements() {
Serial.print("Odleglosc1: ");
Serial.print(measure(TRIGGER1, ECHO1));
Serial.print("cm");
Serial.print(" Odleglosc2: ");
Serial.print(measure(TRIGGER2, ECHO2));
Serial.println("cm");
}
void loop() {
getAndLogMeasurements();
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment