Example #1
0
def pick_speed(speed):
    while not button_b.is_pressed():
        add_text(4, 1, str(speed))
        if button_a.is_pressed():
            speed = speed - 1 if speed > 1 else 9
            sleep(200)
    return speed
Example #2
0
def radio_contact(message): #Fonction d'envoi de données et réception de réponses
        messageArray = message.split("/")
        if messageArray[1] == "cmd":
            status = messageArray[2]
            if (status == "TL"):
                STATUS = "LT"
            else :
                STATUS = "TL"
            temp = str(temperature())
            lum = str(display.read_light_level())
            txt_Temp = "Temp = " + temp
            txt_Lum =  "Lum = " + lum
            if (STATUS == "TL"):
                clear_oled()
                add_text(0, L1, txt_Temp)
                add_text(0, L2, txt_Lum)
            else:
                clear_oled()
                add_text(0, L2, txt_Temp)
                add_text(0, L1, txt_Lum)

        elif messageArray[1] == "ans":
            SENSOR_ID = messageArray[2]

        else:
            radio.send("00/error/umr")
Example #3
0
def displayToScreen(order):  # order is a string
    if order == "TL":
        add_text(0, 0, "Temp : " + str(temperature()) + " C  ")
        add_text(
            0, 1, "Lum : " + str(int(
                (display.read_light_level() / 255) * 100)) + " %  ")
    else:
        add_text(
            0, 0, "Lum : " + str(int(
                (display.read_light_level() / 255) * 100)) + " %  ")
        add_text(0, 1, "Temp : " + str(temperature()) + " C  ")
Example #4
0
        init_message = listen()
        com_established = manage_protocol(init_message, com_established)

    if com_established:
        # Check if we receive a message
        message = listen()
        if message != None:
            # Just want to have two char
            message = message[0:2]
            display.scroll(message)

            if (message == "LT"):
                # LT case
                # Display on screen lum then temp
                clear_oled()
                add_text(0, 0, "L: " + str(display.read_light_level()))
                add_text(0, 1, "T: " + str(temperature()))

                # JSON response, exemple:
                # {"l": "0", "t": "28", "o": "LT"}
                messageReturn = "{\"l\":\"" + str(
                    display.read_light_level()) + "\",\"t\":\"" + str(
                        temperature()) + "\",\"o\":\"" + message + "\"}"

            elif (message == "TL"):
                # TL case
                # Display on screen temp then lum
                clear_oled()
                add_text(0, 0, "T: " + str(temperature()))
                add_text(0, 1, "L: " + str(display.read_light_level()))
Example #5
0
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text
from microbit import *


initialize(pinReset=pin0)
clear_oled()
add_text(0, 0, "Salut !!!")
Example #6
0
from microbit import *
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text

initialize(pinReset=pin0)

while True:
    clear_oled()
    add_text(0, 0, "Temp : " + str(temperature()) + " C")
    add_text(
        0, 1, "Lum : " + str(int(
            (display.read_light_level() / 255) * 100)) + " %")
    sleep(20000)
Example #7
0
    temperature = tmp[3].split(":")[1].replace("[", "")
    light = tmp[4].replace("]", "")
    data = [temperature, light]
    return data


def parsePassword(json):
    tmp = json[1:len(json) - 1]
    tmp = tmp.replace("\"", "")
    tmp = tmp.split(",")
    password = tmp[2].split(":")[1]
    return password


def checkPassword(password):
    return password == NWK_IDFR


while True:
    incomingJSON = radio.receive()
    if incomingJSON != None:
        parsePassword(incomingJSON)
        if checkPassword(parsePassword(incomingJSON)):
            add_text(0, 3, "vrai")
            order = parseData(incomingJSON)[0]
            if (order != DISP_ORD) and (order == "TL" or order == "LT"):
                DISP_ORD = order
    displayToScreen(DISP_ORD)

    radio.send(getJSONToSend())
while True:
    if button_a.is_pressed():
        # opprette tilkobling til OpenLog og skrive overskriftsrad
        uart.init(baudrate=9600, tx=Pin_TX, rx=Pin_RX)
        uart.write("Time;Temp (NTC)\n")
        icon = Image.NO
        while not button_b.was_pressed():
            # finner temperatur og tid og skriver verdiene som en rad
            # til logfila i OpenLog
            temp = round(get_centigrade_temp(),2)
            time = round(utime.ticks_ms()/1000,1)
            row = str(time) + ";" + str(temp)
            uart.write(row + "\n")
            sleep(200)
            if Use_OLED:
                clear_oled()
                add_text(0,1,row)
                sleep(sleeptime)
            else:
                display.scroll(row)
                sleep(max(sleeptime-8000,0))

        # avslutter tilkoblinga til openlog og gjenoppretter mulighet for 
        # tilkobling til PC
        uart.init(baudrate=115200)
        icon = Image.YES
        if Use_OLED:
            clear_oled()

    display.show(icon, delay=400, clear=True)
Example #9
0
def oled_init():
    add_text(0, L1, "initializing")
    add_text(0, L2, "data")
clear_oled()
stamp = create_stamp(Image.HEART)
arrow = create_stamp(Image.ARROW_S)
(x, y, ax, ay, score) = (0, 16, 32, 0, 0)
(x0, y0, ax0, ay0) = (x, y, ax, ay)
while True:
    reading = accelerometer.get_x()
    x = x + 1 if (reading > 20 and x < 58) else x
    x = x - 1 if (reading < -20 and x > 0) else x
    reading = accelerometer.get_y()
    y = y + 1 if (reading > 20 and y < 23) else y
    y = y - 1 if (reading < -20 and y > 0) else y
    if x0 != x or y0 != y:
        move_stamp(x0, y0, x, y, stamp)
        (x0, y0) = (x, y)
    (ay, ax) = (ay + 1, ax) if ay < 31 else (0, randint(0, 58))
    move_stamp(ax0, ay0, ax, ay, arrow)
    (ax0, ay0) = (ax, ay)
    if x == 58:
        x = 0
        score = score + 1
        add_text(2, 3, "Score: " + str(score))
        sleep(1000)
        clear_oled()
    if not ((ax + 5 < x or x + 5 < ax) or (ay + 7 < y + 1 or y + 7 < ay + 1)):
        add_text(2, 1, "GAME OVER")
        add_text(2, 3, "Score: " + str(score))
        sleep(4000)
        clear_oled()
        (score, ay, x) = (0, 0, 0)
Example #11
0
from microbit import sleep
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text
initialize()
clear_oled()
x=20
st='cnt='
while 1:
    y=st+str(x)
    add_text(0,2,y)
    x=x-1
    sleep(20)

Example #12
0
from ssd1306 import draw_screen, clear_oled, initialize
from ssd1306_text import add_text
from kana1 import kana_prt
initialize()
draw_screen()
clear_oled()
kana_prt(0, 0, "a@i@u@e@o@kakikuke-@")
kana_prt(0, 1, "sasisusesotatituteO@")
kana_prt(0, 2, "ZZninunenohahihuhe'@")
add_text(0, 3, "ABCDEFGHIJKL")
draw_screen()
Example #13
0
clear_oled()
spi.init(baudrate=50000, bits=8, mode=0, miso=ECHO_PIN)


def distance():
    gc.disable()
    TRIG_PIN.write_digital(True)
    TRIG_PIN.write_digital(False)
    x = spi.read(200)
    high_bits = 0
    for i in range(len(x)):
        if x[i] == 0 and high_bits > 0:
            break
        elif x[i] == 0xff:
            high_bits += 8
        else:
            high_bits += bin(x[i]).count('1')
    x = None
    gc.enable()
    gc.collect()
    return high_bits * DISTANCE_CM_PER_BIT + DISTANCE_OFFSET


while True:
    dist = distance()
    print(str(dist))
    add_text(2, 1, "Distanz: ")
    add_text(2, 3, str(dist))
    draw_screen()
    sleep(1000)
Example #14
0
from ssd1306 import draw_screen, initialize, clear_oled
from ssd1306_text import add_text

initialize()
clear_oled()
add_text(2, 1, "Hello")
add_text(2, 3, "World!")
draw_screen()
Example #15
0
from microbit import *
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text

initialize()
clear_oled()
while 1:
    y = str(pin1.read_analog())
    add_text(0, 0, y)
Example #16
0
initialize()
clear_oled()
display.show(image)

while machine_active:
    gc.collect()
    speaker.off()
    audio.play(Sound.HAPPY)
    for pixel_id in range(0, len(np)):
        red = randint(0, 60)
        green = randint(0, 60)
        blue = randint(0, 60)
        np[pixel_id] = (red, green, blue)
        np.show()
        sleep(100)
    add_text(0, 0, 'Cupcake Game!')
    valid_choice = False
    choice = input(
        'ORDER [rainbow - salted caramel - dark cherry - bacon bourbon]: ')
    if choice in CHOICES:
        valid_choice = True
    else:
        print('That is not a valid selection...\n')
    if choice == 'shutdown':
        entered_password = input('ENTER SHUTDOWN PASSWORD: '******'YOU ARE NOT AUTHORIZED TO DISABLE THIS MACHINE!\n')
    elif choice == 'stats':
        stats_ = stats(raw_materials, secret_points, total_money_collected)