#include <ESP32Servo.h>
Servo servo;
int rouge = 5;
int vert = 18;
int trig = 12;
int echo = 13;
void setup() {
pinMode(rouge, OUTPUT);
pinMode(vert, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
servo.attach(26);
}
void loop() {
digitalWrite(trig,1);
delay(10);
digitalWrite(trig,0);
int distance = pulsin(echo,1) * 0.034/2;
if (distance < 100){
angle = 0;
servo.write(0);
digitalWrite(rouge,1);
delay(100);
digitalWrite(rouge,0);
digitalWrite(vert,1);
delay(100);
digitalWrite(vert,0);
}
else{
servo.write(90);
}
}