I wanted to put my callsign in morse as a bootup tune in my new DM-1701, so I asked ChatGPT to write a script to help me out. It failed miserably, so I got really annoyed with it and decided to teach it a lesson by showing it how it's done
![Wink ;)](./images/smilies/icon_e_wink.gif)
Here's the resulting script. If you don't have Python installed, you can run it online on this link and just change the morse_code string to whatever you want: Online Python.
Code: Select all
def morse_code_to_boot_tune(morse_code, pitch=38, speed=1):
symbols = {
'.': (1, 1),
'-': (3, 1),
' ': (0, 3),
'/': (0, 7)
}
tune = []
gap = 0
for symbol in morse_code:
if symbol not in symbols:
continue
if gap:
tune.append((0, gap))
tone_length, gap = symbols[symbol]
if (tone_length):
tune.append((pitch, tone_length))
return ','.join([f'{tone},{duration*speed}' for (tone,duration )in tune])
# Morse code for "CQ DMR"
# We use space to denote a gap between letters and slash for gaps between words.
morse_code = "-.-. --.-/-.. -- .-."
pitch = 38
speed = 2
tune_str = morse_code_to_boot_tune(morse_code, pitch, speed)
print(tune_str)
Code: Select all
38,6,0,2,38,2,0,2,38,6,0,2,38,2,0,2,0,6,38,2,0,2,38,6,0,2,38,2,0,2,38,2,0,2,0,6,38,2,0,2,0,6,38,2,0,2,38,6,0,2,0,6,38,6,0,2,38,2,0,2,0,6,38,2,0,2,0,6,38,2,0,2,38,6,0,2,38,2,0,2,0,14,38,6,0,2,38,2,0,2,38,6,0,2,38,2,0,2,0,6,38,6,0,2,38,6,0,2,38,6,0,2,0,6,38,6,0,2,38,2,0,2,38,2,0,2,0,6,38,2,0,2,0,6,38,2,0,2,38,2,0,2,38,6,0,2,38,6,0,2,38,2,0,2,38,2
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Cool 8-)](./images/smilies/icon_cool.gif)
ChatGPT KO'd in coding challenge
73, Thomas OZ5TN