Ahh, thanks... I think getting multiple tones (or even something non-flickery) is going to be properly hard work without using assembler I'm afraid :(
In the code I posted:
new Uint32Array(.. creates a 'view' of the other array (so it doesn't copy it but just lets you see it 24 bits at a time)
[].forEach.call(words, function is a bit grotty (it'll be easier soon), but basically it creates an empty array, 'steals' forEach and calls it as if it was actually a function on Uint32Array. forEach will then call the function defined after it for each of the 32 bit words in the array (but it'll do it quite quickly).
And digitalWrite writes data out to the pins defined in the array, but does so one at a time. That means that you can write the 3 colours out, then write a 1 to B8, and then a 0 to B8.
The crazy multiply/and/shift stuff is to take the top bit of the 8 bit colour in each of 3 bytes, put them together, and move them down to the bottom 3 bits.
Anyway, that and some other tweaks should make it a lot faster, but I think you're still going to have quite a bit of trouble with it...
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ahh, thanks... I think getting multiple tones (or even something non-flickery) is going to be properly hard work without using assembler I'm afraid :(
In the code I posted:
new Uint32Array(..
creates a 'view' of the other array (so it doesn't copy it but just lets you see it 24 bits at a time)[].forEach.call(words, function
is a bit grotty (it'll be easier soon), but basically it creates an empty array, 'steals'forEach
and calls it as if it was actually a function onUint32Array
.forEach
will then call the function defined after it for each of the 32 bit words in the array (but it'll do it quite quickly).digitalWrite
writes data out to the pins defined in the array, but does so one at a time. That means that you can write the 3 colours out, then write a 1 to B8, and then a 0 to B8.Anyway, that and some other tweaks should make it a lot faster, but I think you're still going to have quite a bit of trouble with it...