コード例 #1
0
def process_outgoing(msg):
    # Example of sending a message on a timer
    # Just call microbit.send_message whenever you have new data
    # this will be sent to the gateway micro:bit which will then
    # broadcast it to all listening micro:bit devices
    #  print("tx:%s" % str(msg))
    microbit.send_message(msg)
コード例 #2
0
def process_outgoing(msg):
    # basic send to gateway microbit
    # this message will be sent to the gateway micro:bit which will then
    # broadcast it to all listening micro:bit devices as a scrolled message
    # The s/w will try to access the last used USB port, if this does not work
    # you may have to re-start the Pi
    # If no known USB port s/w will take you through a config exercise first

    microbit.send_message(msg)
コード例 #3
0
def process_sound(sound):
    levels = np.abs((sound['data'] * calib))  #sound['data']
    rgb = []
    if np.mean(levels) > 0.07:
        cry = True
        msg = 'C'
    else:
        cry = False
        msg = 'Q'
    microbit.send_message(msg)
    return
コード例 #4
0
# WORK IN PROGRESS - DO NOT USE

import microbit
import time

# is this how we want it to work?
# This seems really messy
# although we do want a way to pass a custom class in the future too
microbit.use_API(microbit.GATEWAY)
microbit.connect()

# or like this
# I think this is closer to what we want, but not quite right
from microbit import gateway_microbit

gateway_microbit.connect()

# what if we want to force a specific port name rather than use auto detected default?

print("connected")

while True:
    msg = microbit.read_next_message()
    if msg is not None:
        print("got message:%s" % str(msg))
    microbit.send_message("hello")
    time.sleep(0.5)

# END
コード例 #5
0
    elif message == green:
        keyboard.press('g')
        time.sleep(0.1)
        keyboard.release('g')
        print("g")
    elif message == violet:
        keyboard.press('v')
        time.sleep(0.1)
        keyboard.release('v')
        print("v")
    elif message == white:
        keyboard.press('w')
        time.sleep(0.1)
        keyboard.release('w')
        print("w")
    elif message == yellow:
        keyboard.press('y')
        time.sleep(0.1)
        keyboard.release('y')
        print("y")
    else:
        print("error")


print("gateway running")
microbit.send_message("ready\n")

while True:
    msg = microbit.get_next_message()
    if msg is not None:
        process_incoming(msg)
コード例 #6
0
def awaiting_connection():
    # rgb = wifi_rgb[randint(0,5)]
    microbit.send_message('W')
    time.sleep(0.1)
    return