I’m having trouble with my neopixel code.
I use 120 neopixels
I’m trying to make start position from 61 not 0. also end point is 70 not 120.
I tried 100 times to solve this problem…but I can’t
can anyone help me?
here is my core code below.
void loop() {
n.setTime(c.m, c.s);
delay(1000);
}
void NeoPixel::setM(int m)
{
strip.setPixelColor(m, strip.Color(0, 255, 0));
for (uint16_t i = 0; i < strip.numPixels(); i++) {
if (i != m)
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.show();
}
}
void NeoPixel::setS(int s)
{
strip.setPixelColor(s, strip.Color(0, 0, 255));
for (uint16_t i = 61; i <strip.numPixels()-50; i++) {
if (i != s)
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.show();
}
}
void NeoPixel::setTime(int s, int m)
{
//strip.setPixelColor(second, strip.Color(255, 0, 0));
strip.setPixelColor(m, strip.Color(0, 255, 0));
strip.setPixelColor(s, strip.Color(0, 0, 255));
for (uint16_t i = 0; i < strip.numPixels(); i++) {
if (i != s && i != m)
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.show();
}
}
Do you really want to call strip.show() for each iteration of you for() loops or rather build the whole strip first and only show when finished?
The only place where I can see your 61…70 action is NeoPixel::setS(), but you don’t seem to call that anywhere.
And even if, your NeoPixel::setTime() would override that.
BTW, choosing another name for your class rather than NeoPixel might reduce confusion (e.g. npClock or such).
@youja, can you post the reset of your code including setup() and where you create the neopixel object(s). It’s not obvious what you are asking for. You want the “zero” positio to be at pixel 61 and end at pixel 70?
Exactly!
Your loop() only calls n.setTime(c.m, c.s); but n.setTime() does not call setS(), or do you see it called anywhere?
Do we have to explain your code to you?
First, I’d repeat my advice to move the strip.show() commands out of the for() loops, directly after the closing curly brace.
And then you should try changing your loop() to this