...this is really a weird piece of code... with every button 1 press, a new watch on button 1 is created... furthermore, the index runs away... (of course, only after quite many presses). Fixing of the code is removing the first repeating watch and changing the second one to repeat. For the index, remove the modulo in every array access, and replace the simple increment with index = ++index % maxColors;. Looking at why maxColors is needed to be set manually, I decided to give this code a face lift, because it's less to rewrite than instruct what to change to make it ... (you can call it whatever you want).
PS: I assume that creator of this code confused that the original design did not work with repeated watching button 1 outside of the drawColor() function - that no matter what value the repeat(e) option property was given - it just did not work so the watch, the second one inside the loop was established... this time with proper spelling of the repeat: option property...
(...this in the official Espruino repo... @Gordon, I guess introducing an ESR### - like the JSR### - process would give a bit more stability to the code base. To not stifle the contribution process, it could be a two stage app repository, where a new or changed app first goes into a staging mode / area / ... and move into the final place only after community feedback.)
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.
...this is really a weird piece of code... with every button 1 press, a new watch on button 1 is created... furthermore, the index runs away... (of course, only after quite many presses). Fixing of the code is removing the first repeating watch and changing the second one to repeat. For the index, remove the modulo in every array access, and replace the simple increment with
index = ++index % maxColors;
. Looking at why maxColors is needed to be set manually, I decided to give this code a face lift, because it's less to rewrite than instruct what to change to make it ... (you can call it whatever you want).PS: I assume that creator of this code confused that the original design did not work with repeated watching button 1 outside of the drawColor() function - that no matter what value the repeat(e) option property was given - it just did not work so the watch, the second one inside the loop was established... this time with proper spelling of the
repeat:
option property...(...this in the official Espruino repo... @Gordon, I guess introducing an ESR### - like the JSR### - process would give a bit more stability to the code base. To not stifle the contribution process, it could be a two stage app repository, where a new or changed app first goes into a staging mode / area / ... and move into the final place only after community feedback.)