- We no longer require a password
- We support more hubs
- Mention known key issues
- Simplify Chrome 85 discussion
- Add instructions to unplug cables prior to update
This adds the method equivalent to the recent addition of a single
color light. The only difference is that now a color is returned instead
of a single brightness. The provided color or HSV tuple will be stored
as RGB samples internally, as is already done for pbio light patterns.
In the simplest blinking form this could be:
hub.light.pattern(lambda t: Color.RED if t >= 1000 else None, 2000)
Or a fading, one-color sine:
def fade(time):
v = sin(time/2000/pi)*50+50
h = 360
s = 100
return (h, s, v)
hub.light.pattern(fade, 1000)
This makes it much easier to have fine grained control
over colors and cycle through them easily (0--360).
This also makes it consistent with sensor APIs. Now you
can measure the color and plug it into this method.
We can make this change because none of
the implementations use this yet.
If we feel we miss out by dropping the RGB, it would be more fitting
to instead expose R, G, and B attributes which point to instances of
the Light class. However, this is using more memory for something that
isn't very useful.
We could also just provide generic color converters between rgb, hsv,
and perhaps hex html color strings, not tied to any particular light or
sensor.
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().
We are using an older version of Sphinx which does not support
autodoc of inherited class attributes yet. This works
around it by just referencing the EV3 attribute, which does work.
This reflects a firmware update that makes it more consistent with
pybricks-micropython for EV3. Making imports explicit is also more
Pythonic. This will make it clearer when some classes are not available
on some hubs.