Created
August 7, 2025 08:00
-
-
Save MichaelBell/2ae48a31e4be09e3179169aecb851263 to your computer and use it in GitHub Desktop.
TinyQV pwl synth
This file contains hidden or 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
| import machine | |
| import time | |
| def play_raw(raw_period, amplitude, channel): | |
| machine.mem16[0x800_01c0 + 2*channel] = raw_period | |
| machine.mem16[0x800_01c8 + 2*channel] = amplitude | |
| notes = { | |
| 'C': 909, | |
| 'C#': 801, | |
| 'D': 698, | |
| 'D#': 601, | |
| 'E': 510, | |
| 'F': 424, | |
| 'F#': 343, | |
| 'G': 266, | |
| 'G#': 194, | |
| 'A': 125, | |
| 'A#': 61, | |
| 'B': 0 } | |
| def play_note(octave, note, amplitude, channel): | |
| raw_period = (7 - octave) << 10 | |
| raw_period += notes[note] | |
| play_raw(raw_period, amplitude, channel) | |
| def scale(octave, channel): | |
| for note in "CDEFGAB": | |
| play_note(octave, note, 63, 0) | |
| time.sleep(0.2) | |
| play_note(octave+1, "C", 63, 0) | |
| time.sleep(0.3) | |
| for note in "BAGFEDC": | |
| play_note(octave, note, 63, 0) | |
| time.sleep(0.2) | |
| time.sleep(0.1) | |
| play_note(octave, "C", 0, 0) | |
| pin = machine.Pin(7, func_sel=7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment