import utime, random
from time import sleep_us
from machine import Pin, time_pulse_us
utime.sleep(0.1) # Wait for USB to become ready
print("Raspberry Pi Pico wurde gestartet!")
utime.sleep(1)
print("Raspberry Pi Pico & Elemente werden eingerichtet...")
led = Pin(25, Pin.OUT)
led.low()
# LED konfigurieren
LED_R = Pin(10, Pin.OUT)
LED_G = Pin(9, Pin.OUT)
LED_B = Pin(8, Pin.OUT)
# Ultraschallsensor konfigurieren
Ultraschallsensor_Trigger = Pin(3, Pin.OUT)
Ultraschallsensor_Echo = Pin(2, Pin.IN)
utime.sleep(1)
print("Konfiguration abgeschlossen!")
while True:
Ultraschallsensor_Trigger.low()
sleep_us(2)
Ultraschallsensor_Trigger.high()
sleep_us(10)
Ultraschallsensor_Trigger.low()
pulse_duration = time_pulse_us(Ultraschallsensor_Echo, Pin.high)
distance = pulse_duration / 58
if(distance > 250):
LED_B.low()
LED_G.low()
LED_R.low()
elif(distance > 100 and distance < 250):
LED_B.high()
LED_G.low()
LED_R.high()
elif(distance > 50 and distance < 100):
LED_B.high()
LED_G.low()
LED_R.low()
elif(distance > 25 and distance < 50):
LED_B.high()
LED_G.high()
LED_R.low()
elif(distance < 25):
LED_B.value(random.randrange(0, 2, 1))
LED_G.value(random.randrange(0, 2, 1))
LED_R.value(random.randrange(0, 2, 1))
utime.sleep(0.3)