示例#1
0
def send_AT(mSend, mRec1, mRec2=b""):
    while True:
        uart.write(mSend)
        sleep(100)
        if uart.any():
            s = uart.readall()
            if s == mRec1 or s == mRec2:
                break
    display.show(Image.HAPPY)
    sleep(200)
示例#2
0
 def temperature(self):
         try:
             uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=self.tx_pin, rx=self.rx_pin)
             sleep(1)
             uart.write(b'\x50')
             t = 0
             buf = bytearray(1)
             while not uart.any() and t < 1000:
                 t = t + 1
                 sleep(5)
             if t < 1000:
                 uart.readinto(buf, 1)
             uart.init(115200)
             return(buf[0] - 45)
         except Exception as exc:
             uart.init(115200)
             print_exception(exc)
示例#3
0
 def distance_mm(self):
     try:
         uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=self.tx_pin, rx=self.rx_pin)
         sleep(1)
         uart.write(b'\x55')
         t = 0
         buf = bytearray(2)
         while not uart.any() and t < 1000:
             t = t + 1
             sleep(5)
         if t < 1000:
             uart.readinto(buf, 2)
         uart.init(115200)
         dist = buf[0] * 256 + buf[1]
         if dist > 1100:
             dist = -1
         return dist
     except Exception as exc:
         uart.init(115200)
         print_exception(exc)
示例#4
0
import microbit
from microbit import uart

while(True):
    if(uart.any()):
        input = uart.read(1)
        print("Got " + str(input))#was for debugging
        #if first character from input(message) is '1' set light to 9 brightest
        #otherwise if anything else (including '0') set lite to 0 - effectively off
        if(chr(input[0]) == '1'): light = 9
        else: light = 0
        #turn on microbit display
        microbit.display.on()
        #Displays Heart when recieving message ON - using variable light in place of manual setting
        microbit.display.set_pixel(1,0,light)
        microbit.display.set_pixel(3,0,light)
        microbit.display.set_pixel(0,1,light)
        microbit.display.set_pixel(2,1,light)
        microbit.display.set_pixel(4,1,light)
        microbit.display.set_pixel(0,2,light)
        microbit.display.set_pixel(4,2,light)
        microbit.display.set_pixel(1,3,light)
        microbit.display.set_pixel(3,3,light)
        microbit.display.set_pixel(2,4,light)
    
        #for all LEDs on
        #microbit.display.set_pixel(0,0,light)
        #microbit.display.set_pixel(0,1,light)
        #microbit.display.set_pixel(0,2,light)
        #microbit.display.set_pixel(0,3,light)
        #microbit.display.set_pixel(0,4,light)
示例#5
0
    show_id()
    leds_br()

    while True:  # start current measurement
        t_now = ut.ticks_us()

        t_last = ut.ticks_diff(t_now, t_l)
        if send_tick - t_last < 0:  # should send
            t_l = t_now
            if ackd:
                cur_num_tx = cur_num_tx + 1
            ackd = False
            if lu > 0:
                cidx += 1

        if uart.any():
            rl = uart.readline()
            if rl:
                b1 = str(rl, 'UTF-8')
                ur += b1.strip()
                pos = ur.find("=")
                if pos >= 0:
                    ro.send(ur[:pos])
                    ur = ""

        rns = ro.receive_full()
        if rns:
            rxc += 1
            msg = rns[0]
            rssi = rns[1]
            line = str(msg, 'UTF-8')[3:]