Skip to content

Instantly share code, notes, and snippets.

@jay0lee
Last active July 17, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jay0lee/e3cec7b2d126e3887c5c899635aeef90 to your computer and use it in GitHub Desktop.
Save jay0lee/e3cec7b2d126e3887c5c899635aeef90 to your computer and use it in GitHub Desktop.
CircuitPython script for the Raspberry Pi Pico that reads the CPU temperature and displays it in morse code.
# Simple CircuitPython script for the Raspberry Pi Pico that reads the CPU's
# temperature and displays it in morse code https://en.wikipedia.org/wiki/Morse_code
import board
import digitalio
import microcontroller
import time
convert_to_fahrenheit = True
dot = 0.5 # time length of a dot in morse
dash = dot * 3
space = dot
letter = dot * 3
word = dot * 7
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
morse_numbers = [
[dash, dash, dash, dash, dash], # 0
[dot, dash, dash, dash], # 1
[dot, dot, dash, dash, dash], # 2
[dot, dot, dot, dash, dash], # 3
[dot, dot, dot, dot, dash], # 4
[dot, dot, dot, dot, dot], # 5
[dash, dot, dot, dot, dot], # 6
[dash, dash, dot, dot, dot], # 7
[dash, dash, dash, dot, dot], # 8
[dash, dash, dash, dash, dot], # 9
]
def get_temp():
t1 = microcontroller.cpu[0].temperature
t2 = microcontroller.cpu[1].temperature
temp = int(min(t1, t2)) # the cooler CPU is likely closest to ambient temp
if convert_to_fahrenheit:
temp = int(temp * (9 / 5) + 32)
return temp
def convert_int_to_digitlist(number):
'''takes a number and returns a list of the digits'''
''' 119 > [1, 1, 9] '''
return [int(d) for d in str(number)]
while True:
temp = get_temp()
print(f'Temperature is {temp}')
temp_digits = convert_int_to_digitlist(temp)
for d in temp_digits:
m = morse_numbers[d]
print(f'{d}: {m}')
for dot_or_dash in m:
led.value = True
time.sleep(dot_or_dash)
led.value = False
time.sleep(space)
time.sleep(letter)
time.sleep(word)
@Crysknife007
Copy link

This is great! I've forked the code and made a few modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment