Start position of neopixel [Solved]

Hi guys,

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?

you want to affect only pixels 61 through 70?

yes, I want to affect only s pixels 61 through 70.
but it is not affect it.

you mean NeoPixel::setS() doesn’t call anywhere?
well…let me change another name for NeoPixel.

I want to affect only ‘s’ pixels 61 through 70.
but ‘m’ pixels 0 through 60.

@peekay123
Okay, my question is…

‘m’ pixels should be 0 to 60.
‘s’ pixels should be 61 to 70.
‘m’ pixels works fine.
but ‘s’ pixels are not…

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?

@ScruffR
well…yes please
I need to learn more.

Where have you got that code from then?

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

void loop() {
  //n.setTime(c.m, c.s);
  n.setM(c.m);
  n.setS(c.s);

  delay(1000);
}

thanks for reply.
I got this code from web surfing I don’t remember where…

I tried what you wrote.
It works as same as before.

void NeoPixel::setS(int s)
{
  strip.setPixelColor(s, strip.Color(0, 0, 255));
  for (uint16_t i = 61; i <strip.numPixels()-50; i++) {
 // for (uint16_t i = 61; i < 70; i++) {
   
    if (i != s)
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    //strip.show();
  }
  strip.show();
}

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();
  }
 strip.show();
}

void loop() {
  n.setM(c.m);
  n.setS(c.s);
  delay(1000);
}

Could you post your full code then?

I solved this problem.
It was not that simple…anyway thank you for your help.