You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
881 B
42 lines
881 B
#encoding: utf-8
|
|
import machine
|
|
import network
|
|
import socket
|
|
import rp2
|
|
from time import sleep_ms,sleep
|
|
from machine import Pin,PWM
|
|
|
|
led = Pin(15, Pin.OUT)
|
|
pwm = PWM(Pin(15))
|
|
duty_step = 129 # Schrittweite für den Tastgrad
|
|
|
|
|
|
|
|
# Frequenz in Hertz (Hz) einstellen
|
|
# Bei höhren Werten als 100 wird der Piezo Speaker "basslastiger" und die LED
|
|
# erreicht nicht ihre max. Helligkeit.
|
|
# Bei niedrigeren flackert die LED
|
|
pwm.freq(100)
|
|
|
|
# initialer Tastgrad (Duty Cycle)
|
|
pwm.duty_u16(0)
|
|
|
|
try:
|
|
while True:
|
|
# linear ansteigender Tastgrad
|
|
for duty_cycle in range(0, 65536, duty_step):
|
|
pwm.duty_u16(duty_cycle)
|
|
sleep_ms(10)
|
|
|
|
sleep(2)
|
|
|
|
# Linear absteigender Tastgrad
|
|
for duty_cycle in range(65536, 0, -duty_step):
|
|
pwm.duty_u16(duty_cycle)
|
|
sleep_ms(10)
|
|
sleep(2)
|
|
finally:
|
|
print('finally')
|
|
pwm.duty_u16(0)
|
|
pwm.deinit()
|
|
led.off()
|