Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
dbb1c976
Commit
dbb1c976
authored
3 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
demos: Add ws2812 BLE demo
parent
10f10496
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#5435
passed
3 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demos/ble-ws2812-card10.py
+35
-0
35 additions, 0 deletions
demos/ble-ws2812-card10.py
demos/ble-ws2812-host.py
+17
-0
17 additions, 0 deletions
demos/ble-ws2812-host.py
with
52 additions
and
0 deletions
demos/ble-ws2812-card10.py
0 → 100644
+
35
−
0
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
)
This diff is collapsed.
Click to expand it.
demos/ble-ws2812-host.py
0 → 100644
+
17
−
0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment