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.
Usually, images are static, so they can be computed in advance instead of during runtime. This makes scripts smaller and much more memory efficient.
For example, now you can say:
HOUSE = 4685823
hub.grid.image(HOUSE)
since 4685823 =
```
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
```
We could also choose the binary format to allow for more generic screen sizes. If we allow a bit more space (2 words instead of 1), we could do 1 byte per row to allow screens up to 8x8. Right now, though, we choose 1 word < 31 bits which is a bit more efficient in MicroPython.
We can easily list numerous example in the docs or provide a simple visual calculator.
There is still a matrix method that takes a 2D matrix of intensities for full control during runtime, which is what the image() method was doing initially. This commit renames the old draft to matrix().
This removes the default value from the `r` parameter (this was probably copy/paste error from the `draw_box` method). The actual implementation does not have a default value.
- Move it to the class description, because it applies to all methods
- Use minimal and concise language, with only one definition per line, instead of having an elaborate paragraph.
Intellisense in VS Code (both jedi and ms python language server) picks
up all imported names and suggests them with equal priority for
code completion. By adding a leading underscore, intellisense lists
these with a lower priority, so they don't get in the way.
Also rename from builtins to _common while we are touching this to
better reflect the intention of the module (it contains types shared
by multiple modules, not builtin types like int).
The documentation currently has a mix of with and without the `s`.
Adding an `s` is consistent with most API documentation in general,
especially more modern documentation.
This removes versioneer for versioning. The version depends on the
pybricks-micropython version targeted so it doesn't make sense to use
automatic versioning here.
pybricks is a namespace, not a module, so it cannot have __init__.py. Otherwise there can be no other packages installed that use the pybricks namespace.
All point-to-point maneuvers come to a controlled stop before the stop
mode kicks in. Therefore it is more accurate to rename stop_type to
then, as this argument controls what happens after stopping,
so it reads: then=Stop.HOLD.
Partially reverts b25227ec5b
This stays coast by default. This way, stop() remains the best way to release all torque from a motor. Also, it ensures that stopping a running motor or drivebase is smooth by default.