Skip to content

Commit

Permalink
vinscant: beep beep beep & welkom message
Browse files Browse the repository at this point in the history
  • Loading branch information
draxaris1010 authored and hannes-dev committed Jun 11, 2024
1 parent 267da2d commit 17b74d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 8 additions & 3 deletions vinscant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ def gotoSleep(self):
self.idle()


def good(self):
def good(self, name=None):
self.led.setColor(*StatusNotifier.colors[2])
self.buzzer.start(500)
if name:
req.post("http://10.0.2.3", data=f"ScrollingText Welkom {name}!").close()
self.gotoSleep()

def error(self):
self.led.setColor(*StatusNotifier.colors[0])
self.buzzer.start(250)
self.gotoSleep()

watchdog = None

def do_read():
rdr = mfrc522.MFRC522(rst=16,cs=33,sck=34,mosi=35,miso=36)
Expand All @@ -94,10 +97,11 @@ def do_read():
if uid != lastUid or currentTime - lastTime > 5:
res = req.post("https://zess.zeus.gent/scans", data=f"{uid};{key}")
print("vingo: " + res.text)
name = res.text
res.close()
# beep beep
if 200 <= res.status_code < 300:
notifier.good()
notifier.good(name)
else:
notifier.error()
else:
Expand All @@ -112,7 +116,7 @@ def do_read():
watchdog.feed()
except KeyboardInterrupt:
print("KeyboardInterrupt")

watchdog = WDT(timeout=60 * 60 * 1000)
return

notifier = StatusNotifier(Buzzer(Pin(37, Pin.OUT)), Led())
Expand All @@ -122,4 +126,5 @@ def do_read():
time.sleep(2)
watchdog = WDT(timeout=10 * 1000)
print("vinscant: watchdog started")
req.post("http://10.0.2.3", data=f"Option autoResetMs {5 * 1000}").close()
do_read()
7 changes: 3 additions & 4 deletions vinscant/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ def __init__(self, melody: io.IOBase, pin: Pin) -> None:
self.melody = melody
self.pin = pin
self.pwm: PWM = PWM(pin, freq=1, duty_u16=0)
self.timer = Timer(0)
self.timer = Timer(1)

@staticmethod
def midi_to_freq(note: int):
return 440 * 2**((float(note) - 69) / 12)

def start(self):
self.timer.init(mode=Timer.PERIODIC, freq=10, callback=self.playNote)
self.pwm = PWM()
self.timer.init(mode=Timer.PERIODIC, freq=1, callback=self.playNote)

def playNote(self, ignored: Timer):
note = self.melody.read(1)
if len(note) == 0:
self.close()
return
note = note[0]
self.pwm.freq(MusicPlayer.midi_to_freq(note))
self.pwm.freq(int(MusicPlayer.midi_to_freq(note)))
if note == 0:
self.pwm.duty_u16(0)
else:
Expand Down

0 comments on commit 17b74d0

Please sign in to comment.