Programmcode und Schaltungsaufbau

This commit is contained in:
Olli Graf
2024-11-30 14:34:38 +01:00
commit b43fbd9e11
2 changed files with 42 additions and 0 deletions

42
main.py Normal file
View File

@@ -0,0 +1,42 @@
#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()

BIN
pwm_Steckplatine.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 KiB