-1

I need a hand. I'm trying to figure out how to shuffle some neopixel pins. Right now, I have a function that shuffles the pins, but I don't know how to define those pins and start the strips. I've got a pastebin of what I have over here:

http://pastebin.com/kzAv95Yr

Basically what's stumping me is this:

NeoPatterns Strip1(32, neoPixelPins[0], NEO_GRB + NEO_KHZ800, &StripComplete); 

I can't move this into the setup function. So I can't do it after shufflepins() in setup, and I can't move Strip1.begin() etc out of a function or into the start of loop().

So. How can I do this? i need to first shuffle the pins, then define my strips, then start them. This needs to be reusable, because at the end of the game, it re-shuffles all the pins and starts over.

I'm going to have a read through this: Call a function before main

But if someone can give me a hand with this, I would appreciate it. I'm new to C++.

Reference on where the neopatterns class came from: https://learn.adafruit.com/multi-tasking-the-arduino-part-3/using-neopatterns

gre_gor
  • 6,669
  • 9
  • 47
  • 52
mishap_n
  • 578
  • 2
  • 10
  • 23

1 Answers1

0

You want to shuffle the pin numbers, but you want to do that before the constructor is called, is that it?

Much more simply, just call Adafruit_NeoPixel::setPin in setup, once you have shuffled the pins. So you can just pass any old pin numbers in the constructor, and then just change them.

I'm going to have a read through this: Call a function before main

Don't go down that path, it is unnecessarily complicated.


Can you toss an example up for Adafruit_NeoPixel::setPin in setup?

Something like this:

  Strip1.begin();
  Strip2.begin();
  Strip3.begin();

  Strip1.setPin (3);  // or whatever
  Strip2.setPin (4);
  Strip3.setPin (5);

I just gave a simple example, you can do your shuffling and stuff the resulting pins into those three function calls. Now you don't have to worry about shuffling before you make Strip1/Strip2/Strip3.

Nick Gammon
  • 1,173
  • 10
  • 22
  • Yup! That's it. re: I want to shuffle the pins before the constructor is called. Can you toss an example up for Adafruit_NeoPixel::setPin in setup? – mishap_n Feb 08 '16 at 05:23