is it possible to set the brightness on the micro:bit pixels like with micropython?
I don't believe so, no - not without some firmware changes. Did you want to change the brightness of individual pixels, or the whole screen?
Ideally of individual pixels.
I was just reading your excellent page about PWM, calling the microbit.show() function with this technique should do the trick, but probably only for the whole screen/whole images, right?
PS: Espruino is by far the best firmware for the micro:bit, a high-level language AND full BTLE stack!!!
Yes, you could use a sort of PWM - your issue is that under the hood the micro:bit is 'scanning' the display - in 3 parts at 200Hz - so if you're not careful when you try your PWM you could end up with some parts looking brighter than others if the timer used for changing what is shown and the one used for doing the PWM go in and out of phase.
The easiest thing would be to try calling show() in a setInterval and alternating between two different values (maybe try doing it at 50Hz at first, and fiddle with the interval). Pixels that are 1 in both values will be brighter than those that are 1 in only one of them.
Otherwise it'd require some firmware mods and I wonder how you'd expose the functionality. Perhaps a second argument to show() that was another bitmap? It doesn't seem very user-friendly though.
thank you for your reply!
I've tried a couple of things, but I suspect the switching via setInterval is not fast and/or precise enough.
Here is what I've tried so far (trying to get all pixels at 50% brightness):
and this one:
var c = 0;
I thought the last one would be a little bit faster (by removing setTimeout) but nothing changed.
As for a firmware mod, this would be awesome of course!
A nice way to implement it, would be perhaps in your graphics library, while creating the ArrayBuffer:
g = Graphics.createArrayBuffer(5,5,4);
this way we could manage images with 16 levels of gray/brightness directly.
Would this make sense?
The micropython firmware supports 9 levels of brightness (0 is off) and visually it works pretty well, the other official firmware (the js/typescript thing) "supports" 255 levels of brightness, but this really does not work, and all kind of weird things happen (probably the out-of-phase problems you mentioned?)
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem