mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 17:14:41 +00:00
b8505ff218ec0897cc63e2fccafba33ff7aa413c
Currently, Pybricks has system patterns for builtin lights.
This adds a user method to set such a pattern.
For example, an indefinite sine pattern could be specified by
def fade(time):
return sin(time/2000/pi)*50+50
hub.light.pattern(fade, 1000)
or a blinking pattern using
def blink(time):
if time >= 1000:
return 100
else:
return 0
hub.light.pattern(blink, 2000)
or briefly:
hub.light.pattern(lambda t: 100 if t >= 1000 else 0, 2000)
This combines the best of simplicity and efficiency: The user doesn't
have to calculate and provide an expensive list of floating points, but
provide a clean and adaptable method instead.
By sampling, we maintain a fixed length pattern which we can preallocate
for the hub lights, and the samples are calculated only once and the
callable may be garbage collected if given as lambda. Also, any
exceptions will be caught immediately during the one-off evaluation.
Pybricks end-user API & Documentation ===================================== This repository documents the Pybricks end-user MicroPython API. Each `Pybricks firmware`_ comes with the `Pybricks package`_. All modules, classes, methods, and functions in that package have optimized implementations in C for high performance and reduced memory footprint. This repository provides an empty, pure Python blueprint of that package. It is used to generate the `official documentation`_. See the `contributor's guide <CONTRIBUTING.md>`_ for acceptable changes and instructions to build the documentation locally. For general discussion, please visit the `support`_ issue tracker. .. _Pybricks package: pybricks .. _Pybricks firmware: https://github.com/pybricks/pybricks-micropython .. _official documentation: https://docs.pybricks.com/ .. _support: https://github.com/pybricks/support/issues
Languages
Python
99.1%
Shell
0.9%