Created
March 25, 2024 13:13
-
-
Save damp11113/e0203ef0ed5642a5717a3a0962b49318 to your computer and use it in GitHub Desktop.
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
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