0

I am working with a NeoPixel RGB led and have gone through various tutorials but I have a question regarding the setPixelColor().

If I do not have my setPixelColor() and show() inside of a for loop it will not work.

This works:

void holoLight(uint32_t c){
  for(uint16_t i = 0; i<2; i++){
    holo_pxl.setPixelColor(i, c);
    holo_pxl.show();
    delay(2500);
  }
}

This does not:

void holoLight(uint32_t c){
    holo_pxl.setPixelColor(1, c);
    holo_pxl.show();
    delay(2500);
}

I am sure it is something specific to the language or execution but would love some clarifications, thanks =)

  • 1
    Please edit question and say what happens -- ie what colors appear, which lights turn on or off -- rather than ambiguous "works" and "not work" descriptions. Also, to do the same thing in the second version as the first (except for delays) add holo_pxl.setPixelColor(0, c); and report results. – James Waldby - jwpat7 Oct 30 '16 at 3:45
  • 1
    Please show the part of the code that initializes holo_pxl and describes your neopixel device better (is it a matrix? how many LEDs does it have?) – jfpoilpret Oct 30 '16 at 3:50
  • 3
    Out of curiosity, have you tried holo_pxl.setPixelColor(0, c);instead of holo_pxl.setPixelColor(1, c); in the second example? – jfpoilpret Oct 30 '16 at 3:51
  • @jfpoilpret you were spot on, I can't believe I skipped something so simple. Thanks for the help =) – afreeland Oct 30 '16 at 20:19
4

I am not sure I fully understand your exact problem but you have to be aware that holo_pxl.setPixelColor(1, c); set the color of the second LED in a NeoPixel chain, NOT the first one.

For the first LED, you have to use holo_pxl.setPixelColor(0, c); instead.

  • 1
    #facepalm...it would be something so simple. I switched out an 8 led neopixel stick for a single rgb neopixel...and didnt think about it being zero-based index. As embarrassing as this post is I will leave up for anyone else that overlooks the obvious coding late into the night o.O – afreeland Oct 30 '16 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.