Added some micro:bit projects I previously did in here
This commit is contained in:
0
bin/micro_bit/micro_bit_soft/decoder/decoder.py
Normal file
0
bin/micro_bit/micro_bit_soft/decoder/decoder.py
Normal file
36
bin/micro_bit/micro_bit_soft/decoder/encoder.py
Normal file
36
bin/micro_bit/micro_bit_soft/decoder/encoder.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# create class that encodes plain text into morse
|
||||
|
||||
class Encoder:
|
||||
# init class
|
||||
def __init__(self):
|
||||
# Morse code dict
|
||||
self.morse_code = {'A': '.-', 'B': '-...',
|
||||
'C': '-.-.', 'D': '-..', 'E': '.',
|
||||
'F': '..-.', 'G': '--.', 'H': '....',
|
||||
'I': '..', 'J': '.---', 'K': '-.-',
|
||||
'L': '.-..', 'M': '--', 'N': '-.',
|
||||
'O': '---', 'P': '.--.', 'Q': '--.-',
|
||||
'R': '.-.', 'S': '...', 'T': '-',
|
||||
'U': '..-', 'V': '...-', 'W': '.--',
|
||||
'X': '-..-', 'Y': '-.--', 'Z': '--..',
|
||||
'1': '.----', '2': '..---', '3': '...--',
|
||||
'4': '....-', '5': '.....', '6': '-....',
|
||||
'7': '--...', '8': '---..', '9': '----.',
|
||||
'0': '-----', 'Ä': '.-.-', 'Ö': '---.',
|
||||
'Ü': '..--', ',': '--..--', '.': '.-.-.-',
|
||||
'?': '..--..', '/': '-..-.', '-': '-....-',
|
||||
'(': '-.--.', ')': '-.--.-', ':': '---...',
|
||||
'!': '-.-.--', ' ': '@'}
|
||||
self.__input_raw = ""
|
||||
self.__output = []
|
||||
self.__pos = 0
|
||||
|
||||
def encode(self):
|
||||
self.__input_raw = self.get_input()
|
||||
for self.item in self.__input_raw:
|
||||
self.__code = self.morse_code.get(self.item)
|
||||
self.__output.append(self.__code)
|
||||
return self.__output
|
||||
|
||||
def get_input(self):
|
||||
return input("please input some text here to transmit: ").upper()
|
||||
5
bin/micro_bit/micro_bit_soft/decoder/exec.py
Normal file
5
bin/micro_bit/micro_bit_soft/decoder/exec.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import run
|
||||
|
||||
m = run.Morse()
|
||||
|
||||
m.run()
|
||||
3
bin/micro_bit/micro_bit_soft/decoder/log_generator.py
Normal file
3
bin/micro_bit/micro_bit_soft/decoder/log_generator.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class LogGenerator:
|
||||
def __init__(self):
|
||||
pass
|
||||
28
bin/micro_bit/micro_bit_soft/decoder/run.py
Normal file
28
bin/micro_bit/micro_bit_soft/decoder/run.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import music
|
||||
|
||||
import encoder
|
||||
import music
|
||||
|
||||
|
||||
mdc = encoder.Encoder()
|
||||
|
||||
|
||||
class Morse:
|
||||
def __init__(self):
|
||||
self.__encoded = []
|
||||
self.__sound_duration = 50
|
||||
|
||||
def run(self):
|
||||
self.__encoded = mdc.encode()
|
||||
self.output_gen()
|
||||
|
||||
def output_gen(self):
|
||||
for self.item in self.__encoded:
|
||||
for self.ec in self.item:
|
||||
if self.ec == ".":
|
||||
music.pitch(440, self.__sound_duration)
|
||||
elif self.ec == "-":
|
||||
music.pitch(440, self.__sound_duration * 3)
|
||||
|
||||
|
||||
Morse().run()
|
||||
Reference in New Issue
Block a user