I'm not sure I understand what you're doing - for each LED you're completely wiping the screen with fillRect for most patterns - so it's going to be insanely slow and almost certainly not what you want.
If you want to see the lights on the screen, remove all the LCD calls you have, and change doLights to:
function doLights() {
getPattern();
for (var i=0;i<rgb.length;i+=3) {
LCD.setColor(rgb[i+0]/256,rgb[i+1]/256,rgb[i+2]/256);
LCD.fillRect(i,0,i+2,10);
}
SPI2.send4bit(rgb, 0b0001, 0b0011);
}
Your actual problem is changePattern(). It actually works fine until you press the button?
For some reason you've actually commented out the code that made it work - so unsurprisingly it's now broken.
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.
LCD
is actually built-in on the HY STM32 boards.I'm not sure I understand what you're doing - for each LED you're completely wiping the screen with fillRect for most patterns - so it's going to be insanely slow and almost certainly not what you want.
If you want to see the lights on the screen, remove all the LCD calls you have, and change
doLights
to:Your actual problem is
changePattern()
. It actually works fine until you press the button?For some reason you've actually commented out the code that made it work - so unsurprisingly it's now broken.
should be:
The percent is a 'modulo' - basically if patternNumber gets bigger than the number of patterns then it rolls over back to 0.
Without it, patternNumber gets bigger, and you try and access something in the patterns array that doesn't exist, which gives you undefined.
Finally, you probably also want to debounce the switch, so use:
instead of just
setWatch(changePattern, BTN, { repeat: true, edge:'rising' });