Hey Particle Team. I am programming using an Ada fruit neopixel 24 ring. I am trying to make it so that every five LEDs the six would glow a different color (15, 15, 15). I attempted to do the following to the code with no luck. Any idea why? - Please go easy on me, I am a beginner!
encoderPosition = encoderPos;
//Serial.println(encoderPosition);
buttonState = digitalRead(button);
for (int i = 0; i < encoderPosition; i != 6; i != 12; i != 18; i != 24; i++) {
ring.setPixelColor(i, 0, 15, 0); //LED of Timer
}
for (int i = 6; i = 12; i = 18, i = 24; i = encoderPosition; i++) {
ring.setPixelColor(i, 15, 15, 15); //LED of Timer
}
for (int i = encoderPosition; i <= 25; i++) {
ring.setPixelColor(i, 0, 0, 0); //If count passed LED 25, go dark or don't do anything
OK, it doesn’t do what you want, but what does it do?
I’d be surprised when this code even compiled (for() only likes two semicolons inside the parentheses).
Anyway since your first for() loop would never make it past i == 6 the other portions are superfluous anway.
Not quite sure what you exactly intend to do, but one thing I could imagine you want may be like this
encoderPosition = constrain(encoderPosition, 0, 23); // limit LED number to allowed range
for (int i = 0; i <= encoderPosition; i++) {
if ( (i+1) % 6 )
ring.setPixelColor(i, 0, 15, 0);
else
ring.setPixelColor(i, 15, 15, 15);
}
for (int i = ++encoderPosition; i < 24; i++) // clear the remaining LEDs
ring.setPixelColor(i, 0, 0, 0);
Alternatively you could use a switch() block instead of the if() ... else ...
switch(i+1) {
case 6:
case 12:
case 18:
case 24:
ring.setPixelColor(i, 15, 15, 15);
break;
default:
ring.setPixelColor(i, 0, 15, 0);
break;
}
ring.show() is required to push the values changed to the LEDs? Otherwise nothing will be shown/change!
When you say glow do you mean glow as in light and then dim in a cycle or just stay the same brightness? If you want to glow (light and dim) then ring.setColorDimmed() can be used. There are various “simple” ways to get a wave going around the ring by using a static array of 24 brightness values and iterating this each cycle using the modulus (%) value as the index. Hours of fun!