#include <ultrasonic.h>
#include <SevSeg.h>
int pins= {27,26,12,13,14,23,22};
const int triggerPin = 4;
const int echoPin = 2;
void setup() {
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
// Measure the time it takes for the pulse to return
long duration = pulseIn(echoPin, HIGH);
// Convert the time to distance (cm)
float distance = duration * 0.034 / 2;
// Display the distance on the 7-segment display if it's less than 10cm
if (distance < 10) {
sevseg.setNumber(distance, 1);
sevseg.refreshDisplay();
}
// Wait for a short delay before taking the next measurement
delay(100);
}