Beispiel #1
0
            splash.remove(carret)
        else:
            splash.append(carret)

        carret_blink_state = not carret_blink_state
        carret_blink_time = time.monotonic()

    # Get UART incoming data and print to terminal on screen
    if uart.in_waiting > 0:
        uart_in = uart.read(uart.in_waiting)

        print(uart_in)
        term.write(uart_in)

    # Process keyboard
    if kbd.key_count > 0:
        k = kbd.key
        if k[0] == STATE_RELEASE:
            if k[1] == '\x08':  # Backspace
                if len(input_text.text) > 0:
                    input_text.text = input_text.text[:-1]
            elif k[1] == '\n':  # Enter, send over UART
                text = input_text.text + '\n'
                uart.write(text.encode('utf-8'))

                input_text.text = ''
            else:  # Anything else, we add to the text field
                input_text.text += k[1]

            carret.x = input_text.x + input_text.bounding_box[2] + 1
    if cur_b_val and not old_b_val:  # if the button was released
        print("b released")
        if CUR_STATE != STATE_DISCHARGING:
            CUR_STATE = STATE_DISCHARGING
        else:
            CUR_STATE = STATE_IDLE
    # print(cur_time)
    if last_tick_time + TICK_INTERVAL <= cur_time:
        last_tick_time = cur_time
        if CUR_STATE == STATE_DISCHARGING:
            discharge_tick()
        elif CUR_STATE == STATE_CHARGING:
            charge_tick()
        # print("{} - charge_level: {:4} charge_brightness: {:4}".format(CUR_STATE, charge_level, charge_brightness))
        new_progress = charge_level / MAX_CHARGE_LEVEL
        text_brightness.text = "Brightness: {:3} %".format(int((charge_brightness / MAX_CHARGE_BRIGHTNESS) * 100))
        new_width = int(board.DISPLAY.width * new_progress)
        rect.x = -240 + new_width

        if CUR_STATE == STATE_DISCHARGING:
            if charge_level > 0:
                led.duty_cycle = max(200, charge_brightness)
            else:
                CUR_STATE = STATE_IDLE
                charge_brightness = 0
        else:
            led.duty_cycle = 0
    old_a_val = cur_a_val
    old_b_val = cur_b_val
Beispiel #3
0
            x_pos = left_scroll
            right_scroll = left_scroll
        #  if you press right on the 5-way switch...
        if not right.value and right_state is None:
            # print("scroll", down_scroll)
            right_state = "pressed"
            #  track the switch's position
            right_scroll += 1
            if right_scroll > 3:
                right_scroll = 0
            x_pos = right_scroll
            left_scroll = right_scroll

        #  update square's position on the GUI
        rect.y = select_y[y_pos]
        rect.x = select_x[x_pos]

        #  update the currently highlighted button on the GUI
        for coords in switch_coordinates:
            if x_pos == coords[0] and y_pos == coords[1]:
                button_pos = switch_coordinates.index(coords)
                #  print(button_pos)
        button_num = text_labels[button_pos].text

        #  if you press select on the 5-way switch...
        if not select.value and select_state is None:
            select_state = "pressed"
            #  grab the selected button's MIDI note
            midi_num = int(button_num)
            #  change into the secondary GUI menu
            sub_state = True