Skip to content

Instantly share code, notes, and snippets.

@ZappaBoy
Last active August 26, 2022 10:00
Show Gist options
  • Save ZappaBoy/4f154e567798fe5288311c054b7d8648 to your computer and use it in GitHub Desktop.
Save ZappaBoy/4f154e567798fe5288311c054b7d8648 to your computer and use it in GitHub Desktop.
Convert frequencies to marlin gcode sound
song = [
# Add here your song as tuples of (frequency, duration) or better (Hz, seconds)
# Check both:
# - Song example - https://gist.github.com/ZappaBoy/563533bb4d9a9cbc2709a75b84bc37fb
# - Output example - https://gist.github.com/ZappaBoy/701bbab166b0573b71be7e889f0af575
]
def convert_song(notes):
lines = []
for note in notes:
frequency = note[0]
duration = note[1]
lines.append(f"M300 S{frequency} P{duration}\n")
with open('output.txt', 'w') as f:
f.writelines(lines)
if __name__ == '__main__':
convert_song(song)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment