#Bibliothèque
import time
from machine import Pin, I2C, time_pulse_us
from time import sleep
from servo import Servo
from ssd1306 import SSD1306_I2C
#Déclaration
button1 = Pin(13, Pin.IN, Pin.PULL_UP)
button2 = Pin(10, Pin.IN, Pin.PULL_UP)
ledv=Pin(2,Pin.OUT)
ledr=Pin(4,Pin.OUT)
ledo=Pin(3,Pin.OUT)
servo = Servo(20)
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
oled = SSD1306_I2C(128, 64, i2c)
vitesse_son = 340
trig = Pin(27,Pin.OUT) # envoyer les ondes
echo = Pin(28,Pin.IN) # recevoir les ondes
TRIG_PULSE_US=1
#code
oled.fill(0)
oled.text("System Pret", 0, 20)
oled.show()
ledr.value(0)
ledv.value(0)
servo.move(0)
while True:
trig.value(0)
trig.value(1) #initialiser le capteur
time.sleep(TRIG_PULSE_US) # Donner une impulsion au capteur
trig.value(0)
ultrason = time_pulse_us(echo, 1, 30000)
distance = vitesse_son * ultrason / 20000
print (f"Distance : {distance} cm" )
sleep(2)
oled.fill(0)
if not button1.value() == 1 and button2.value() ==1 and distance <10:
ledv.value(1)
oled.text("Bienvenue", 0, 0)
ledr.value(0)
servo.move(180)
else:
ledv.value(0)
ledr.value(1)
servo.move(90)
oled.text("Pas de bienvenue", 0, 0)
oled.show()
sleep(2)