Padded single digit LED identifiers to two chars (01,02 vs 1,2 etc)

This commit is contained in:
Matt Johnson 2017-11-22 23:20:10 +00:00
parent 7a059a1a14
commit d5befdb3eb

View file

@ -74,7 +74,7 @@ void handleSetSingleLED(uint8_t * mypayload, uint8_t firstChar = 1) {
strncpy ( templed, (const char *) &mypayload[firstChar], 2 );
uint8_t led = atoi(templed);
if (led < strip.numPixels()) {
if (led <= strip.numPixels()) {
ledstates[led].red = ((rgb >> 16) & 0xFF);
ledstates[led].green = ((rgb >> 8) & 0xFF);
ledstates[led].blue = ((rgb >> 0) & 0xFF);
@ -118,8 +118,14 @@ void handleRangeDifferentColors(uint8_t * mypayload) {
while ( rangebegin <= rangeend ) {
char rangeData[9] = { 0,0,0,0,0,0,0,0,0 };
if ( rangebegin < 10 ) {
//Create the valid 'nextCommand' structure
sprintf(rangeData, "0%d%s", rangebegin, colorval);
}
if ( rangebegin >= 10 ) {
//Create the valid 'nextCommand' structure
sprintf(rangeData, "%d%s", rangebegin, colorval);
}
//Set one LED
handleSetSingleLED((uint8_t*) rangeData, 0);
rangebegin++;