コード例 #1
0
def won():
    on = 1

    while True:
        # flash key 15
        if on:
            keypad.illuminate(15, 0x00, 0x80, 0x00)
            on = 0
        else:
            keypad.illuminate(15, 0x00, 0x00, 0x00)
            on = 1

        keypad.update()
        time.sleep(1)

        # return when key 15 is pressed
        if keypad.get_button_states() == 32768:
            return
コード例 #2
0
import time
import picokeypad as keypad

keypad.init()
keypad.set_brightness(1.0)

lit = 0
last_button_states = 0
colour_index = 0

NUM_PADS = keypad.get_num_pads()
while True:
    button_states = keypad.get_button_states()
    if last_button_states != button_states:
        last_button_states = button_states
        if button_states > 0:
            if lit == 0xffff:
                # all buttons are already lit, reset the test
                lit = 0
                colour_index += 1
                if colour_index >= 6:
                    colour_index = 0
            else:
                button = 0
                for find in range(0, NUM_PADS):
                    # check if this button is pressed and no other buttons are pressed
                    if button_states & 0x01 > 0:
                        if not (button_states & (~0x01)) > 0:
                            lit = lit | (1 << button)
                        break
                    button_states >>= 1