Example #1
0
slide_switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
slide_switch.pull = digitalio.Pull.UP
button_a = digitalio.DigitalInOut(board.BUTTON_A)
button_a.pull = digitalio.Pull.DOWN
button_b = digitalio.DigitalInOut(board.BUTTON_B)
button_b.pull = digitalio.Pull.DOWN

led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()

neopixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)

i = 0
advertisement = AdafruitColor()
advertisement.color = color_options[i]
neopixels.fill(color_options[i])
while True:
    # The first mode is the color selector which broadcasts it's current color to other devices.
    if slide_switch.value:
        print("Broadcasting color")
        ble.start_advertising(advertisement)
        while slide_switch.value:
            last_i = i
            if button_a.value:
                i += 1
            if button_b.value:
                i -= 1
            i %= len(color_options)
            if last_i != i:
                color = color_options[i]
INTERVAL_TICKS = (33, 37, 41, 43, 47)  ### Do not use 32 here due to fp issues
INTERVAL_TICK_MS = 0.625
MAX_JITTER_DELAY_S = 0.009

##scan_and_ad_time = 30
##scan_response_request = True
scan_and_ad_time = 10
scan_response_request = False

ble = BLERadio()

my_addr_text = addr_to_text(ble.address_bytes)

ca_ad = AdafruitColor()
ca_ad.color = 0x112233

interval = MIN_AD_INTERVAL
##interval = INTERVAL_TICKS[random.randrange(len(INTERVAL_TICKS))] * INTERVAL_TICK_MS / 1e3

### Turn off updates to stop any delays from screen updates on CLUE
if display is not None:
    display.auto_refresh = False


def tx_rx_test(round_no,
               debug=debug,
               manual_jitter=False,
               duration=scan_and_ad_time):
    d_print(2, "TXing", ca_ad, "interval", interval)
    rx_byaddr = {}
Example #3
0
    0x221111, 0x112211, 0x111122
]

i = 0
### Trick to force a first color "change"
last_i = -1

print("Broadcasting color")

### The original code has two mode, the Feather nRF52840 version is broadcasts only.
while True:

    ### If the color has change, or if this is the first time, start advertising the color and set the RGB as feedback indicator.
    if last_i != i:
        last_i = i
        color = color_options[i]
        rgb[0] = ((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF)
        print("New color {:06x}".format(color))
        advertisement.color = color
        ble.stop_advertising()
        ble.start_advertising(advertisement)
        time.sleep(0.5)

### Verify if the user press the button (false if pressed) and change color.
    if not switch.value:
        i += 1
        i %= len(color_options)

### We should never reach this point because of the infinit loop.
ble.stop_advertising()