// عمرو رأفت السيد محمد فتح الله
// سكشن 6
// 200458
#include <Servo.h>
Servo s;
#define echo 2
#define trigger 3
int distance ;
long duration ;
void setup() {
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
s.attach(26);
s.write(0);
pinMode(trigger , OUTPUT);
pinMode(echo , INPUT);
}
void loop() {
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
duration = pulseIn(echo, HIGH);
distance = duration * 0.034 / 2;
Serial1.print("Distance: ");
Serial1.println(distance);
if(distance >= 200){
s.write(180);
}else{
s.write(45);
}
delay(2000);
}