Last active 1700878528

https://blahaj.zone/notes/9mehzr6pjs5zsfs8

Revision cdf5c337277dd9807bf052e57241768555debd96

main.py Raw
1import machine
2import utime
3
4notes = {
5 "B3": 247,
6 "E4": 330,
7 "FS4": 370,
8 "GS4": 415,
9 "A4": 440,
10 "D7": 2349,
11}
12
13green = machine.Pin(25, machine.Pin.OUT)
14green.value(0)
15
16buzzer = machine.PWM(machine.Pin(22))
17
18rtc=machine.RTC()
19#timestamp=rtc.datetime()
20#file = open("test","a")
21#file.write("%04d-%02d-%02d %02d:%02d:%02d.%04d\n"%(timestamp[0:3] + timestamp[4:8]))
22#file.close()
23
24#minute = [
25# ("D7", 0.1)
26#]
27#hour = [
28# ("GS4", 0.4),
29# ("E4", 0.4),
30# ("FS4", 0.4),
31# ("B3", 0.4),
32# ("", 0.4),
33# ("", 0.4),
34# ("B3", 0.4),
35# ("FS4", 0.4),
36# ("GS4", 0.4),
37# ("E4", 0.4)
38#]
39minute = [("D7", 0.1)]
40hour = [("D7", 0.4)]
41
42while True:
43 timestamp=rtc.datetime()
44# print("%04d-%02d-%02d %02d:%02d:%02d.%04d"%(timestamp[0:3] + timestamp[4:8]))
45 song = []
46 # internal RTC starts on 2021-01-01 00:00:01.0000
47 if timestamp[6]-1 == 0:
48 if timestamp[5] == 0:
49 song = hour
50 else:
51 song = minute
52 for note,length in song:
53 if length > 0.5:
54 raise Exception
55 green.value(1)
56 if note:
57 buzzer.freq(notes[note])
58 buzzer.duty_u16(1000)
59 utime.sleep(length)
60 green.value(0)
61 if note:
62 buzzer.duty_u16(0)
63 utime.sleep(0.5-length)
64 if len(song)%2 != 0:
65 utime.sleep(0.5)
66 else:
67 utime.sleep(1)