#include <Ultrasonic.h>
Ultrasonic sensor(9, 8);
int val;
int buzz = 6;
int high;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = sensor.read(CM);
high = val * -1 + 255;
if(val <= 100)
{
analogWrite(buzz, high);
}
else{
digitalWrite(buzz, LOW);
}
Serial.print(val);
Serial.println(" cm");
delay(50);
}