BBR Button Board Documentation

Your first script#

A companion app is a loop: read what the robot is doing, decide what the panel should look like, push it.

from bb import Board

with Board.open() as board:
    leds = board.led_layer()

    while True:
        arm_fault = read_from_networktables("arm_fault")
        in_range  = read_from_networktables("in_scoring_range")

        leds.set(3, "red" if arm_fault else "off")
        leds.set(7, "green" if in_range else "off", fx="breathe")
        leds.flush()

led_layer() or board.led()#

board.led(3, "red") sends a command every time you call it, whether or not the colour changed.

led_layer() stages the writes and flush() sends only what changed. Use it for anything that runs in a loop; use board.led() for one-off changes.

leds.set(3, "red")
leds.flush()        # sends: led 3 FF0000
leds.set(3, "red")
leds.flush()        # sends nothing

Colours#

A colour can be given as:

leds.set(1, "red")             # a name
leds.set(2, "#0040FF")         # hex, with or without the #
leds.set(3, (0, 64, 255))      # an (r, g, b) triple
leds.set(4, 0x0040FF)          # an int
leds.set(5, None)              # off

Named colours include red green blue yellow cyan magenta orange purple pink amber lime teal white off, plus alliance_red and alliance_blue.

Effects#

leds.set(3, "red", "blink")       # slow flash
leds.set(3, "red", "fast")        # fast flash
leds.set(3, "red", "breathe")     # fade in and out

An effect keeps running with no further commands.

Clearing up#

board.led_reset()      # back to the colours saved in the configuration
board.led_all("off")   # everything dark, right now

led_all("off") is the panic button: it overrides anything else in progress.

When the board goes away#

If the board is disconnected, every call raises BoardError:

from bb import Board, BoardError

try:
    leds.flush()
except BoardError as e:
    print("lost the panel:", e)
    # reconnect, then leds.forget() so the next flush redraws everything

Call forget() after a reconnect or a board reboot, so the next flush() resends everything.