-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pybricks.ble.Broadcast: Send tuple of data.
This makes it easy to send and receive up to 8 values at once without having to encode them manually.
- Loading branch information
1 parent
61aaa19
commit a72d891
Showing
4 changed files
with
294 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2021 The Pybricks Authors | ||
|
||
""" | ||
Hardware Module: Technic Hub (ble1_technic.py) and Prime Hub (ble1_prime.py) | ||
Description: Tests broadcast receive and transmit. | ||
""" | ||
|
||
from pybricks.hubs import PrimeHub | ||
from pybricks.parameters import Color | ||
from pybricks.tools import wait | ||
from pybricks.ble import Broadcast | ||
|
||
from umath import pi | ||
|
||
hub = PrimeHub() | ||
hub.light.on(Color.WHITE) | ||
|
||
# Initialize broadcast with two topics. | ||
radio = Broadcast(topics=["data"]) | ||
|
||
# This hub only sends, so we can turn off scanning. | ||
radio.scan(False) | ||
|
||
for i in range(20): | ||
|
||
# Send a number | ||
counter = radio.send("data", 123) | ||
wait(1000) | ||
|
||
# Send a large number and a float | ||
counter = radio.send("data", (-456789, pi)) | ||
wait(1000) | ||
|
||
# Send even more. | ||
counter = radio.send("data", ("or", 1.234, "this!")) | ||
wait(1000) | ||
|
||
# Send nothing, to clear their data. | ||
counter = radio.send("data", None) | ||
wait(1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2021 The Pybricks Authors | ||
|
||
""" | ||
Hardware Module: Technic Hub (ble2_technic.py) and Prime Hub (ble2_prime.py) | ||
Description: Tests broadcast receive and transmit. | ||
""" | ||
|
||
from pybricks.hubs import TechnicHub | ||
from pybricks.parameters import Color | ||
from pybricks.tools import wait | ||
from pybricks.ble import Broadcast | ||
|
||
hub = TechnicHub() | ||
hub.light.on(Color.WHITE) | ||
|
||
# Initialize broadcast with one topic. | ||
radio = Broadcast(["data"]) | ||
|
||
for i in range(100): | ||
|
||
# Get the data topic. | ||
data = radio.receive("data") | ||
print(data) | ||
|
||
wait(1000) |