Skip to content

Instantly share code, notes, and snippets.

@damp11113
Created March 25, 2024 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damp11113/e0203ef0ed5642a5717a3a0962b49318 to your computer and use it in GitHub Desktop.
Save damp11113/e0203ef0ed5642a5717a3a0962b49318 to your computer and use it in GitHub Desktop.
import board
import digitalio
import time
import simpleio
def string_to_binary_list(input_string):
binary_list = []
for char in input_string:
# Convert each character to its ASCII value and then to binary
binary_char = bin(ord(char))[2:]
# Pad the binary representation with leading zeros to ensure it's 8 bits long
binary_char = '0' * (8 - len(binary_char)) + binary_char
binary_list.append(binary_char)
return binary_list
def tx(string, bitrate=320):
speed = 1 / bitrate
for bin_char in string_to_binary_list(string):
for bit in bin_char:
if bit == "0":
simpleio.tone(board.GP0, 1000, duration=speed)
elif bit == "1":
simpleio.tone(board.GP0, 2000, duration=speed)
#time.sleep(speed)
while True:
tx("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment