Skip to content

Commit 479771f

Browse files
committed
Show RSSI with the number of pixels lit
1 parent 1c28c1e commit 479771f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

examples/ble_color_proximity.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
0x000011,
2222
0x110011,
2323
0x111111,
24-
0x111111,
25-
0x0,
26-
0x0]
24+
0x221111,
25+
0x112211,
26+
0x111122]
2727

2828
ble = BLERadio()
2929

@@ -37,7 +37,7 @@
3737
led = digitalio.DigitalInOut(board.D13)
3838
led.switch_to_output()
3939

40-
neopixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
40+
neopixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
4141

4242
i = 0
4343
advertisement = AdafruitColor()
@@ -71,7 +71,7 @@
7171
closest_last_time = 0
7272
print("Scanning for colors")
7373
while not slide_switch.value:
74-
for entry in ble.start_scan(AdafruitColor, minimum_rssi=-80, timeout=1):
74+
for entry in ble.start_scan(AdafruitColor, minimum_rssi=-100, timeout=1):
7575
if slide_switch.value:
7676
break
7777
now = time.monotonic()
@@ -84,5 +84,16 @@
8484
continue
8585
closest_rssi = entry.rssi
8686
closest_last_time = now
87-
neopixels.fill(entry.color)
87+
discrete_strength = min((100 + entry.rssi) // 5, 10)
88+
#print(entry.rssi, discrete_strength)
89+
neopixels.fill(0x000000)
90+
for i in range(0, discrete_strength):
91+
neopixels[i] = entry.color
92+
neopixels.show()
93+
94+
# Clear the pixels if we haven't heard from anything recently.
95+
now = time.monotonic()
96+
if now - closest_last_time > 1:
97+
neopixels.fill(0x000000)
98+
neopixels.show()
8899
ble.stop_scan()

0 commit comments

Comments
 (0)