Raspberry Pi Pico W ( Niveau 1 )
About Lesson
from machine import Pin 
import utime  
trig = Pin( 0 , Pin.OUT , value = 0 )
echo = Pin(1 , Pin.IN)
RelayIn = Pin(2 , Pin.OUT , value = 0)
RelayOut = Pin(3 , Pin.OUT , value = 0 )
button = Pin(4 , Pin.IN , Pin.PULL_UP)
D = 320 
h = 0
def ultrason():
    t = Toff = Ton = distance = 0
    trig.on()
    utime.sleep_us(10)
    trig.off()
    while echo.value() == 0 :
        Toff = utime.ticks_us()
    while echo.value() == 1 :
        Ton = utime.ticks_us()
    t  = (Ton - Toff ) / 2 
    distance =  int( t * 0.034)
    h = 320 - distance 
    Hpercent = int(h * (100/300))
    print(button.value())
    if  210 < h <= 270 :
        RelayIn.on()
        RelayOut.on()
    elif  h <= 210 :
        RelayOut.off()
        RelayIn.on()
    else :
        RelayIn.off()
        RelayOut.on()
#void loop : boucle infinie 
while 1 :
    while button.value() == 0 :
        ultrason()
        utime.sleep_ms(50)
    else :
        pass

Join the conversation
0% Complete
error: Content is protected !!

تم إرسال طلبك بنجاح وسنتواصل معك قريباً