-
-
Save Crysknife007/52fe9f8ff9ec83d863984e03dce43409 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Circuit Python Script that Blinks the Current Temperature in Celsius in Morse Code | |
# Modified July 2022 by Spike Snell from jay0lee's code below on github: | |
# https://gist.github.com/jay0lee/e3cec7b2d126e3887c5c899635aeef90 | |
# Import all that we need | |
import board, digitalio, microcontroller, time | |
# Define the length of a dot | |
dot = 0.25 | |
# Define dash length as three times dot length | |
dash = dot * 3 | |
# Define the word length as seven times dot length | |
word = dot * 7 | |
# Define the onboard LED | |
led = digitalio.DigitalInOut(board.LED) | |
# Set the LED direction to OUTPUT | |
led.direction = digitalio.Direction.OUTPUT | |
# Define our morse numbers | |
morse_numbers = [ | |
[dash, dash, dash, dash, dash], # 0 | |
[dot, dash, 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 | |
] | |
# This function converts an int to a digit list | |
def convert_int_to_digitlist(number): | |
return [int(d) for d in str(number)] | |
# Loop forever | |
while True: | |
# Get the current temperature of the microcontroller | |
temp = int(microcontroller.cpu.temperature) | |
# Print the current temperature | |
print(f'C: {temp}') | |
# Get the temperature digit list | |
temp_digits = convert_int_to_digitlist(temp) | |
# For every digit in the temp_digits list | |
for d in temp_digits: | |
# Get the morse numbers | |
m = morse_numbers[d] | |
# Print the morse numbers | |
print(f'{d}: {m}') | |
# For every dot or dash in m | |
for dot_or_dash in m: | |
# Set the LED value to true | |
led.value = True | |
# Sleep for the dot or dash time as appropriate | |
time.sleep(dot_or_dash) | |
# Set the LED value to false | |
led.value = False | |
# Sleep for a dot length of time | |
time.sleep(dot) | |
# Sleep for a dash time between each letter | |
time.sleep(dash) | |
# Sleep for a word amount of time between each temperature indication | |
time.sleep(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There was an issue with the dot and dash list for the digit #1. I've also made some other modifications and comments, and updated the code to work with more up to date versions of circuit python.