Last active
August 8, 2023 15:19
-
-
Save jvanvinkenroye/8e8136ea64b3f281bd8cfc1e4bba4568 to your computer and use it in GitHub Desktop.
dht_play.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bibliotheken laden | |
from machine import Pin | |
from time import sleep | |
from picodfplayer import DFPlayer | |
# Initialisierung des PIR-Moduls | |
pir = Pin(22, Pin.IN, Pin.PULL_DOWN) | |
# Initialisierung der Onboard-LED | |
led = Pin(25, Pin.OUT, value=0) | |
# Initialisierung DFPlayer (UART, TX-Pin, RX-Pin, Busy-Pin) | |
player = DFPlayer(0, 16, 17, 18) | |
sleep(1) | |
player.setVolume(15) # Lautstärke einstellen: 0 bis 30 | |
# PIR-Ruhezustand abwarten | |
print('Warten') | |
print() | |
sleep(3) | |
print('Bereit') | |
print() | |
# Funktion bei Bewerbungserkennung | |
def pir_handler(pin): | |
# PIR-Sensor-Zustand lesen | |
pir_value = pir.value() | |
if pir_value == 1: | |
# Alarm auslösen | |
player.nextTrack() | |
# Warten, bis sich der Bewegungssensor beruhigt hat | |
sleep(10) | |
print('Ruhezustand') | |
print() | |
# Initialisierung Interrupt für die Bewegungserkennung | |
pir.irq(trigger=Pin.IRQ_RISING, handler=pir_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment