Added some micro:bit projects I previously did in here
This commit is contained in:
0
bin/log/logging.md
Normal file
0
bin/log/logging.md
Normal file
@@ -1,3 +0,0 @@
|
|||||||
import microbit
|
|
||||||
|
|
||||||
microbit.uart.write()
|
|
||||||
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()
|
||||||
11
bin/micro_bit/micro_bit_soft/full_duplex.py
Normal file
11
bin/micro_bit/micro_bit_soft/full_duplex.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from microbit import *
|
||||||
|
import music
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.is_pressed():
|
||||||
|
pin1.write_digital(True)
|
||||||
|
elif pin2.read_digital() == 1:
|
||||||
|
music.pitch(440, 50, wait=False)
|
||||||
|
else:
|
||||||
|
music.stop()
|
||||||
|
pin1.write_digital(False)
|
||||||
16
bin/micro_bit/micro_bit_soft/half_duplex.py
Normal file
16
bin/micro_bit/micro_bit_soft/half_duplex.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from microbit import *
|
||||||
|
import music
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.is_pressed() is True:
|
||||||
|
if pin1.read_digital() == 1:
|
||||||
|
display.show(Image.NO)
|
||||||
|
else:
|
||||||
|
pin1.write_digital(1)
|
||||||
|
else:
|
||||||
|
music.stop()
|
||||||
|
pin1.write_digital(0)
|
||||||
|
if pin1.read_digital() == 1:
|
||||||
|
music.pitch(440, 50, wait=False)
|
||||||
|
else:
|
||||||
|
music.stop()
|
||||||
10
bin/micro_bit/micro_bit_soft/listen.py
Normal file
10
bin/micro_bit/micro_bit_soft/listen.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from microbit import *
|
||||||
|
import music
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if pin1.read_digital() == 1:
|
||||||
|
music.pitch(440, 50, wait=False)
|
||||||
|
display.set_pixel(2, 2, 9)
|
||||||
|
else:
|
||||||
|
display.clear()
|
||||||
|
music.stop()
|
||||||
2
bin/micro_bit/micro_bit_soft/micro_bit_soft.py
Normal file
2
bin/micro_bit/micro_bit_soft/micro_bit_soft.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import microbit
|
||||||
|
|
||||||
11
bin/micro_bit/micro_bit_soft/sender.py
Normal file
11
bin/micro_bit/micro_bit_soft/sender.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import music
|
||||||
|
from microbit import *
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if button_a.is_pressed() is True:
|
||||||
|
pin1.write_digital(1)
|
||||||
|
music.pitch(440, 50, wait=False)
|
||||||
|
else:
|
||||||
|
music.stop()
|
||||||
|
pin1.write_digital(0)
|
||||||
|
|
||||||
Reference in New Issue
Block a user