commit 675516b28bceda1907aaeb089bde243b331c0271 Author: Thomas Lindner Date: Mon Dec 23 01:08:03 2024 +0100 initial commit diff --git a/freude.py b/freude.py new file mode 100644 index 0000000..2ce983f --- /dev/null +++ b/freude.py @@ -0,0 +1,22 @@ +import csv + +steps_per_mm = 5 +# starting from C3 = 130.81 Hz +frequencies = [2**(i/12) * 130.81 for i in range(24)] +base_duration = 0.12 + +with open("FREUDE.gcode", "w") as f: + f.write("G21 ; set units to millimeters\n") + f.write("G90 ; use absolute coordinates\n") + f.write("G0 Z10 F300\n") + f.write("G0 X0 Y0 F3000\n") + f.write("G4 S1 ; wait 1 second\n") + position = 0 + with open("freude.txt", "r") as notes: + for note, duration in csv.reader(notes): + feedrate = int(frequencies[int(note) + 12] * 60 / steps_per_mm) + length = int(duration) * base_duration / 60 * feedrate + position += -length if position > 100 else length + f.write(f"G0 X{position:.6f} Y{position:.6f} F{feedrate} \n") + f.write("G4 P15 ; wait a bit\n") + f.write("G4 ; wait\n") diff --git a/freude.txt b/freude.txt new file mode 100644 index 0000000..51a1c6c --- /dev/null +++ b/freude.txt @@ -0,0 +1,62 @@ +4,2 +4,2 +5,2 +7,2 +7,2 +5,2 +4,2 +2,2 +0,2 +0,2 +2,2 +4,2 +4,3 +2,1 +2,4 +4,2 +4,2 +5,2 +7,2 +7,2 +5,2 +4,2 +2,2 +0,2 +0,2 +2,2 +4,2 +2,3 +0,1 +0,4 +2,2 +2,2 +4,2 +0,2 +2,2 +4,1 +5,1 +4,2 +0,2 +2,2 +4,1 +5,1 +4,2 +2,2 +0,2 +2,2 +-8,2 +4,4 +4,2 +5,2 +7,2 +7,2 +5,2 +4,2 +2,2 +0,2 +0,2 +2,2 +4,2 +2,3 +0,1 +0,4