freude/freude.py
2024-12-23 01:08:03 +01:00

23 lines
829 B
Python

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")