update
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import serial
|
||||
import time
|
||||
import bin.com.lib
|
||||
|
||||
|
||||
lb = bin.com.lib.Com()
|
||||
|
||||
|
||||
class CommandListGenerator:
|
||||
def __init__(self):
|
||||
self.__go = 0
|
||||
self.__received = ""
|
||||
self.__start = 0
|
||||
self.__lfcount = 0
|
||||
self.__total = ""
|
||||
self.__output = []
|
||||
|
||||
def run(self, special_port):
|
||||
# This function asks the micro:bit to send a list of all of the commands the program that runs
|
||||
# on it supports. Sent string: "\ncmdl\n". Please note: if using micropython, use the here included
|
||||
# com module to communicate (you can flash it to the micro:bit through the settings menu and also
|
||||
# add your own modules to the micro:bit.
|
||||
try:
|
||||
lb.connect(19200, special_port)
|
||||
self.__go = 1
|
||||
except serial.SerialException as e:
|
||||
return e
|
||||
if self.__go == 1:
|
||||
self.__start = time.time()
|
||||
lb.send("\ncmdl\n")
|
||||
self.__go = 0
|
||||
while time.time() - self.__start < 5:
|
||||
self.__received = lb.receive(1)
|
||||
if self.__received == "\n":
|
||||
self.__received = lb.receive(1)
|
||||
if self.__received == "c":
|
||||
self.__received = lb.receive(1)
|
||||
if self.__received == "m":
|
||||
self.__received = lb.receive(1)
|
||||
if self.__received == "d":
|
||||
self.__go = 1
|
||||
break
|
||||
if self.__go == 1:
|
||||
self.__total = ""
|
||||
self.__output = []
|
||||
lb.receive(1)
|
||||
while self.__lfcount < 3:
|
||||
self.__received = lb.receive(1)
|
||||
if self.__received == "\n":
|
||||
self.__lfcount += 1
|
||||
else:
|
||||
self.__lfcount = 0
|
||||
if self.__received == " ":
|
||||
self.__output.append(self.__total)
|
||||
self.__total = ""
|
||||
else:
|
||||
self.__total += self.__received
|
||||
return self.__output
|
||||
|
||||
5
bin/micro_bit/micro_bit_soft/common/basic_filtering.py
Normal file
5
bin/micro_bit/micro_bit_soft/common/basic_filtering.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class BasicFiltering:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def standard_lib(self):
|
||||
@@ -24,6 +24,7 @@ class Encoder:
|
||||
'(': '-.--.', ')': '-.--.-', ':': '---...',
|
||||
'!': '-.-.--', ' ': '@'}
|
||||
self.__input_raw = ""
|
||||
self.__input = ""
|
||||
self.__output = []
|
||||
self.__pos = 0
|
||||
self.check = 0
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
class LogGenerator:
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -8,4 +8,3 @@ while True:
|
||||
else:
|
||||
music.stop()
|
||||
pin1.write_digital(0)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import microbit
|
||||
|
||||
microbit.uart.write()
|
||||
|
||||
microbit.uart.init(19200)
|
||||
while True:
|
||||
m = microbit.uart.read(1)
|
||||
if m is not None:
|
||||
microbit.display.scroll(str(m))
|
||||
else:
|
||||
microbit.display.clear()
|
||||
|
||||
42
bin/micro_bit/micro_bit_soft/radio_com/basic.py
Normal file
42
bin/micro_bit/micro_bit_soft/radio_com/basic.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import microbit
|
||||
import radio
|
||||
|
||||
|
||||
class Basic:
|
||||
def __init__(self):
|
||||
self.__rx = ""
|
||||
self.__decode = 0
|
||||
self.__go = 0
|
||||
self.d = 0
|
||||
self.__x = 0
|
||||
self.__y = 0
|
||||
|
||||
def run(self, group):
|
||||
radio.config(group=group)
|
||||
radio.on()
|
||||
while True:
|
||||
self.receive_p()
|
||||
|
||||
def receive_p(self):
|
||||
self.__rx = radio.receive()
|
||||
try:
|
||||
self.__decode = int(self.__rx)
|
||||
self.__go = 1
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if self.__go == 1:
|
||||
for self.i in range(self.__decode):
|
||||
self.d = self.i / 2
|
||||
self.__y = self.d % 4
|
||||
self.__x = self.d // 4
|
||||
if self.__x and self.__y < 4:
|
||||
microbit.display.set_pixel(self.__x, self.__y, 9)
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
m = Basic()
|
||||
m.run(11)
|
||||
30
bin/micro_bit/micro_bit_soft/radio_com/run.py
Normal file
30
bin/micro_bit/micro_bit_soft/radio_com/run.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import microbit
|
||||
import radio
|
||||
import basic_filtering
|
||||
import struct
|
||||
|
||||
|
||||
bf = basic_filtering.BasicFiltering()
|
||||
|
||||
|
||||
class RadioCom:
|
||||
def __init__(self):
|
||||
microbit.uart.init(19200)
|
||||
|
||||
def run(self, group):
|
||||
radio.config(group=group)
|
||||
radio.on()
|
||||
|
||||
def inst(self):
|
||||
pass
|
||||
|
||||
def sendpc(self, info):
|
||||
microbit.uart.write(info)
|
||||
|
||||
def listen(self):
|
||||
# listens for messages, sends received text to PC if possible
|
||||
# also returns value, None, if no data is being received
|
||||
radio.receive()
|
||||
|
||||
def send(self, message):
|
||||
radio.send(str(message))
|
||||
Reference in New Issue
Block a user