### it is always 0-10 rather than -5 to 5

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)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP

# Setup BLE connection
ble = BLERadio()

# The color pickers will cycle through this list
color_options = [
    0x110000, 0x111100, 0x001100, 0x001111, 0x000011, 0x110011, 0x111111
]

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

advertisement = AdafruitColor()

# a simple SG90 micro servo is used as meter
pwm = pulseio.PWMOut(board.D5, duty_cycle=2**15, frequency=50)
servo1 = servo.Servo(pwm, min_pulse=500, max_pulse=2100)
servo1.angle = 180

# Uncomment if you use a real 3.3V meter
# meter = pulseio.PWMOut(board.A0, frequency=5000, duty_cycle=0)

# Piezo buzzer
buzzer = pulseio.PWMOut(board.A2, variable_frequency=True)
buzzer.duty_cycle = 0

# 6 LEDs are used in the receiver. The order is important
led_pins = [board.A3, board.D12, board.D11, board.D10, board.D9, board.D6]
Exemple #3
0
ble = BLERadio()

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:
Exemple #4
0
switch.direction = Direction.INPUT
switch.pull = Pull.UP

### Configure the DotStar available on the ItsyBitsy nRF52840
import adafruit_dotstar as dotstar

# On-board DotStar for boards including Gemma, Trinket, and ItsyBitsy
rgb = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
rgb.brightness = 0.3
rgb[0] = (0, 0, 0)

from adafruit_ble import BLERadio
from adafruit_ble.advertising.adafruit import AdafruitColor

ble = BLERadio()
advertisement = AdafruitColor()

# The color pickers will cycle through this list with buttons A and B.
color_options = [
    0x110000, 0x111100, 0x001100, 0x001111, 0x000011, 0x110011, 0x111111,
    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: