Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
dbb1c976
Commit
dbb1c976
authored
Dec 27, 2021
by
schneider
Browse files
demos: Add ws2812 BLE demo
parent
10f10496
Pipeline
#5435
passed with stages
in 1 minute
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/ble-ws2812-card10.py
0 → 100644
View file @
dbb1c976
import
ws2812
,
gpio
,
bluetooth
,
time
,
display
from
micropython
import
const
_IRQ_GATTS_WRITE
=
const
(
3
)
WS2812_SERVICE_UUID
=
\
bluetooth
.
UUID
(
"23230300-2342-2342-2342-234223422342"
)
SET_ALL
=
(
bluetooth
.
UUID
(
"23230301-2342-2342-2342-234223422342"
),
bluetooth
.
FLAG_WRITE
)
WS2812_SERVICE
=
(
WS2812_SERVICE_UUID
,
(
SET_ALL
,)
)
def
irq
(
event
,
data
):
if
event
==
_IRQ_GATTS_WRITE
:
conn_handle
,
value_handle
=
data
value
=
ble
.
gatts_read
(
value_handle
)
ws2812
.
set_all
(
gpio
.
WRISTBAND_3
,
[
value
]
*
3
)
if
__name__
==
"__main__"
:
display
.
open
().
backlight
(
0
)
gpio
.
set_mode
(
gpio
.
WRISTBAND_3
,
gpio
.
mode
.
OUTPUT
)
ble
=
bluetooth
.
BLE
()
ble
.
active
(
True
)
ble
.
irq
(
irq
)
ble
.
gatts_register_services
((
WS2812_SERVICE
,))
print
(
"Waiting for connection!"
)
while
True
:
time
.
sleep
(
1
)
demos/ble-ws2812-host.py
0 → 100644
View file @
dbb1c976
#!/usr/bin/env python3
import
bluepy
import
time
import
colorsys
p
=
bluepy
.
btle
.
Peripheral
(
"CA:4D:10:01:ff:64"
)
c
=
p
.
getCharacteristics
(
uuid
=
'23230301-2342-2342-2342-234223422342'
)[
0
]
hue
=
0
while
1
:
r
,
g
,
b
=
colorsys
.
hsv_to_rgb
(
hue
,
1
,
0.1
)
c
.
write
(
b
"%c%c%c"
%
(
int
(
r
*
255
),
int
(
g
*
255
),
int
(
b
*
255
)),
True
)
time
.
sleep
(.
1
)
hue
+=
0.1
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment