aboutsummaryrefslogtreecommitdiff
path: root/gen.py
diff options
context:
space:
mode:
authorAnthony Wang2022-10-02 15:58:49 -0400
committerAnthony Wang2022-10-02 15:58:49 -0400
commit0cff9a981ff20f9486217c34cda4417db922fb28 (patch)
tree7cc7b0ed1b97f0c2e745acf6a66140b512280372 /gen.py
parentd69b7a62dd7e4a2a4f4c4848ae6c98b638c25638 (diff)
🤔
Diffstat (limited to 'gen.py')
-rw-r--r--gen.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/gen.py b/gen.py
new file mode 100644
index 0000000..de82486
--- /dev/null
+++ b/gen.py
@@ -0,0 +1,35 @@
+with open('nevergonnagiveyouup.ino') as f:
+ lines = f.readlines()
+
+note_to_freq = {}
+
+tempo = 1
+
+with open('rickroll.sh', 'w') as f:
+ for line in lines:
+ if '#define' in line:
+ split = line.split()
+ note_to_freq[split[1]] = split[2]
+ elif 'NOTE' in line:
+ split = line.split(',')
+ note = True
+ for word in split:
+ word = word.replace(' ', '')
+ print(word)
+ if '//' in word or word == '\n':
+ continue
+ elif 'NOTE' in word:
+ f.write(f'beep -f {note_to_freq[word]}')
+ note = True
+ elif 'REST' in word:
+ f.write('sleep')
+ note = False
+ else:
+ d = int(word)
+ if d < 0:
+ d /= -1.5
+ l = (60000 * 4)/150/d
+ if note:
+ f.write(f' -l {l}\n')
+ else:
+ f.write(f' {l/1000}\n')