#Aus der machine-Bibliothek importiere die Klassen Pin und PWM
from machine import Pin, PWM
from time import sleep
led = Pin(15, Pin.OUT)
pwmled = PWM(Pin(16), freq=5000)
class Led0:
def blink():
led.on()
sleep(0.1)
led.off()
sleep(0.2)
class Led1:
def dimmen():
pwmled.duty_u16(655*2) # 65535/100 ~= 655 --> 655*2 ~= 2%
sleep(0.5)
pwmled.duty_u16(round((65535/100)*4))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*8))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*16))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*32))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*64))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*92))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*100))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*92))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*64))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*32))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*16))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*8))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*4))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*2))
sleep(0.5)
pwmled.duty_u16(round((65535/100)*0))
sleep(0.5)
def dim_for():
for i in range(0,65536,+1):
pwmled.duty_u16(i)
sleep(0.1)
for j in range(65535,-1,-1):
pwmled.duty_u16(i)
sleep(0.1)
def dim_for_rosa():
steps = [2, 4, 8, 16, 32, 64, 92, 100, 92, 64, 32, 16, 8, 4, 2, 0]
for schritt in steps:
pwmled.duty_u16(round((65535 / 100) * schritt))
sleep(0.5)
while True == True: # Immer wahr --> Endlosschleife
#Led0.blink()
#Led1.dimmen()
Led1.dim_for_rosa()
Led1.dim_for()