|
| 1 | +""" |
| 2 | +Eddystone Beacon for CLUE |
| 3 | +This example broadcasts our Mac Address as our Eddystone ID and a link to a URL of your choice. |
| 4 | +Hold the A button to display QR code, use B button to pick URL from the list. |
| 5 | +""" |
| 6 | + |
| 7 | +import time |
| 8 | +from adafruit_pybadger import pybadger |
| 9 | +import adafruit_ble |
| 10 | +from adafruit_ble_eddystone import uid, url |
| 11 | + |
| 12 | +radio = adafruit_ble.BLERadio() |
| 13 | + |
| 14 | +# Reuse the BLE address as our Eddystone instance id. |
| 15 | +eddystone_uid = uid.EddystoneUID(radio.address_bytes) |
| 16 | + |
| 17 | +# List of URLs to broadcast here: |
| 18 | +ad_url = [("https://circuitpython.org", "CirPy"), |
| 19 | + ("https://adafru.it/discord","DISCORD"), |
| 20 | + ("https://forums.adafruit.com", "Forums"), |
| 21 | + ("https://learn.adafruit.com", "Learn") |
| 22 | + ] |
| 23 | +pick = 0 # use to increment url choices |
| 24 | + |
| 25 | +pybadger.play_tone(1600, 0.25) |
| 26 | +pybadger.show_business_card(image_name="cluebeacon.bmp") |
| 27 | + |
| 28 | +while True: |
| 29 | + pybadger.auto_dim_display(delay=3, movement_threshold=4) |
| 30 | + eddystone_url = url.EddystoneURL(ad_url[pick][0]) |
| 31 | + |
| 32 | + if pybadger.button.a and not pybadger.button.b: # Press button A to show QR code |
| 33 | + pybadger.play_tone(1200, 0.1) |
| 34 | + pybadger.brightness = 1 |
| 35 | + pybadger.show_qr_code(data=ad_url[pick][0]) # Tests QR code |
| 36 | + time.sleep(0.1) # Debounce |
| 37 | + |
| 38 | + elif pybadger.button.b and not pybadger.button.a: # iterate through urls to broadcast |
| 39 | + pybadger.play_tone(1600, 0.2) |
| 40 | + pick = (pick + 1) % len(ad_url) |
| 41 | + pybadger.brightness = 1 |
| 42 | + pybadger.show_business_card(image_name="bg.bmp", name_string=ad_url[pick][1], name_scale=5, |
| 43 | + email_string_one="", email_string_two=ad_url[pick][0]) |
| 44 | + time.sleep(0.1) |
| 45 | + |
| 46 | + elif pybadger.button.a and pybadger.button.b: |
| 47 | + pybadger.play_tone(1000, 0.2) |
| 48 | + pybadger.brightness = 1 |
| 49 | + pybadger.show_business_card(image_name="cluebeacon.bmp") |
| 50 | + time.sleep(0.1) |
| 51 | + |
| 52 | + # Alternate between advertising our ID and our URL. |
| 53 | + radio.start_advertising(eddystone_uid) |
| 54 | + time.sleep(0.5) |
| 55 | + radio.stop_advertising() |
| 56 | + |
| 57 | + radio.start_advertising(eddystone_url) |
| 58 | + time.sleep(0.5) |
| 59 | + radio.stop_advertising() |
| 60 | + |
| 61 | + time.sleep(1) |
0 commit comments