b.selected = True
                command = (10 * int(active_page)) + b.id

                # Not doing anything wiht the buttons right now.
                # Just dumping out the associated command
                if (b in buttons):
                    print("Button {} pressed on page {}. Running command {}".
                          format(b.label, active_page, command))

                # Change the active page with the tab
                if b == tab0:
                    active_page = 0
                    print("Setting active page to {}".format(active_page))
                    active_fill = active_outline = page0_color
                    main_page.fill = page0_color
                    main_page.outline = page0_color

                elif b == tab1:
                    active_page = 1
                    print("Setting active page to {}".format(active_page))
                    active_fill = active_outline = page1_color
                    main_page.fill = page1_color
                    main_page.outline = page1_color

                elif b == tab2:
                    active_page = 2
                    print("Setting active page to {}".format(active_page))
                    active_fill = active_outline = page2_color
                    main_page.fill = page2_color
                    main_page.outline = page2_color
Exemple #2
0
            sound_on = True
        elif (buttons & BUTTON_SEL) > 0:
            sound_on = False
            if dac.playing:
                dac.stop()

    # Pull in the latest data
    temperature = us100.temperature
    distance = us100.distance
    dist_text_area.text = str(round(distance/30.48, 2)) + "'"

    # Update display elements
    if distance < TriggerDistance:
        print(TxtUnsafe, distance)
        top_text_area.text = TxtUnsafe
        rect.fill = BGUnsafe
        pixel.fill((255, 0, 0))
        if not dac.playing and sound_on:
            dac.play(alert)
    else:
        print(TxtSafe)
        top_text_area.text = TxtSafe
        rect.fill = BGSafe
        pixel.fill((0, 255, 0))
        if dac.playing:
            dac.stop()

    # Flip the display
    display.show(display_group)

    # Sleep until next cycle