Example #1
0
def txp(did,ty,v):
    if ty==1:
        txt = "1,1,%i,%i" %(ms,cs)
    elif ty==2:
        txt = "1,2,%i,%i,%s" %(ms,cs,v)
    elif ty==3:
        #sensing_str = "%i,%i,%i,%i,%i,%i" % (int(pin_logo.is_touched()),display.read_light_level(),a_x,a_y,a_z,compass.heading())
        a_x,a_y,a_z = accelerometer.get_values()
        sensing_str = "%i,%i,%i,%i,%i,%i" % (int(pin_logo.is_touched()),di.read_light_level(),microphone.sound_level(),a_x,a_y,a_z)
        txt = "1,3,%i,%i,%i,%s" %(ms,cs,v, sensing_str)

    elif ty==20:
        txt = "1,20,%s" %(v)
    else:
        txt = "1,%i,%s" %(ty,v)
    tx(did,txt)
Example #2
0
def wait_start():
    global uids, lid, joystick, car_enabled
    go = 0
    while True:
        if button_b.was_pressed():
            joystick = 1
            di.show("J")
            go = 1
        if pin_logo.is_touched():
            di.show("E")
            go = 1
        if button_a.was_pressed():
            go = 1
            car_enabled = 1
            move_motor_lr(0, 0)
            di.show("C")
        if go == 1:
            sleep(500)
            di.clear()
            uids = find_used_ids()
            gnid(uids)
            break
Example #3
0
player = EscapeRoomPlayer('Mr. George')
game = Game()

game_on = True
while game_on:
    display.show(Image(grid.update(player)))

    player_move = True
    while player_move:
        if button_a.is_pressed():
            player.move_west(grid)
            player_move = False
        elif button_b.is_pressed():
            player.move_east(grid)
            player_move = False
        elif pin_logo.is_touched():
            player.move_north(grid)
            player_move = False
        elif pin2.is_touched():
            player.move_south(grid)
            player_move = False

    player_found_gold = game.generate_question(grid, player)
    player_response = None
    while player_found_gold:
        if button_a.is_pressed():
            player_response = 1
            did_player_win = game.did_player_win(grid, player, player_response)
            player_found_gold = False
            if did_player_win:
                game_on = False
def quiz_m(teq):
    """
    Function to handle multiple choice quiz
    
    Params:
        teq: dict
    """
    # Init LED happy image
    display.show(Image.HAPPY)

    # This is an advanced topic as well however this little function
    # cleans out the unnecessary global objects or variables on what
    # we call the heap area in memory
    gc.collect()

    # Init score object
    score = 0

    # Here we iterate through our quiz database with multiple
    # choice items
    for key in teq:
        display.show(Image.SURPRISED)
        print(key)
        say(str(key), speed=SPEED)
        display.show(Image.HAPPY)
        time.sleep(1)

        display.show(Image.SURPRISED)
        print('Press A for {0}.'.format(teq[key][0]))
        say('Press Ayyy for', speed=SPEED)
        say(str(teq[key][0]), speed=SPEED)
        display.show(Image.HAPPY)
        time.sleep(1)

        display.show(Image.SURPRISED)
        print('Touch the logo for {0}.'.format(teq[key][1]))
        say('Toch the logo for', speed=SPEED)
        say(str(teq[key][1]), speed=SPEED)
        display.show(Image.HAPPY)
        time.sleep(1)

        display.show(Image.SURPRISED)
        print('Press B for {0}.'.format(teq[key][2]))
        say('Press B for', speed=SPEED)
        say(str(teq[key][2]), speed=SPEED)
        display.show(Image.HAPPY)
        while True:
            if button_a.is_pressed():
                response = 0
                break
            elif pin_logo.is_touched():
                response = 1
                break
            elif button_b.is_pressed():
                response = 2
                break
            else:
                pass

        correct_answer = teq[key][3]
        display.show(Image.SURPRISED)
        print('You selected {0}.'.format(teq[key][response]))
        say('You selected', speed=SPEED)
        say(str(teq[key][response]), speed=SPEED)
        display.show(Image.HAPPY)
        time.sleep(1)

        if response == correct_answer:
            display.show(Image.SURPRISED)
            print('CORRECT!')
            say('CORRECT!', speed=SPEED)
            display.show(Image.HAPPY)
            score += 1
        else:
            display.show(Image.SURPRISED)
            print('The correct answer is {0}.'.format(
                teq[key][correct_answer]))
            say('The correct answer is', speed=SPEED)
            say(str(teq[key][correct_answer]), speed=SPEED)
            display.show(Image.HAPPY)

        time.sleep(1)
        gc.collect()

    # Here we reply to the student their score
    display.show(Image.SURPRISED)
    print('You got {0} out of {1} correct!'.format(score, len(teq)))
    say('You got', speed=SPEED)
    say(str(score), speed=SPEED)
    say('out of', speed=SPEED)
    say(str(len(teq)), speed=SPEED)
    say('correct!', speed=SPEED)
    display.show(Image.HAPPY)
    time.sleep(1)

    # If student got a perfect score respond appropriately
    # or provide an encouring message to retry the quiz
    display.show(Image.SURPRISED)
    if score == len(teq):
        print('You got a perfect score!')
        say('You got a perfect score!', speed=SPEED)
        print('Well done!')
        say('Well done!', speed=SPEED)
        print('I am so proud of you!')
        say('I am so proud of you!', speed=SPEED)
        play(POWER_UP)
    else:
        print('You are doing a great job!')
        say('You are doing a great job!', speed=SPEED)
        print('I would LOVE for you to try again!')
        say('I would LOVE for you to try again!', speed=SPEED)

    # Display happy response at the end of the quiz
    display.show(Image.HAPPY)
    time.sleep(1)
    gc.collect()
Example #5
0
                if button_a.was_pressed():
                    #di.clear()
                    ctrl_mode ^= 1

                if cmdc % 2 == 0:
                    c3idx %= lu
                    did = uids[c3idx]
                    c3idx += 1
                    txp(did, 10, lid)

                if cmdc % 10 == 0:
                    c2idx %= lu
                    did = uids[c2idx]
                    c2idx += 1
                    if pin_logo.is_touched():
                        selecting = 1
                        scid = did
                        di.show(did)
                        txp(did, 20, did)

                    else:
                        if scid > 0:
                            if not pin_logo.is_touched():
                                cid = scid
                                scid = 0
                                stop = 0
                        txp(did, 25, [0, 0, 60])

            cmdc += 1