[SOLVED] Controlling a NeoPixel Ring

Hi @dcdenison

Some of the errors above are because you seem to have put setup() and loop() function into a C++ file (a-rainbow2.cpp) instead of a sketch (.ino file) or a C file. In C/C++ compilers a function call to a C function has a different low-level calling pattern than that for a C++ method. Since the setup() and loop() functions are already defined in the main function in the Particle source code as C functions, you should put your setup() and loop() functions in a C or sketch (.ino) file.

I had a feeling something like that was going on. How do I change that? Iā€™m working in the Particle IDE.

Thanks for checking it out.

DC

That was (would have been) the answer to my first "provocative" question. But unfortunately there are two (maybe three) Particle IDEs - Particle Dev and Particle Build (aka Web IDE) and Particle CLI, which isn't really an IDE but a build tool.
But I assume it's Build, which would bring me back to the prototypes. In Build I'd go for commenting these two prototypes (even if the comment suggests different)

    // Prototypes for local build, ok to leave in for Build IDE
    void rainbow(uint8_t wait);
    uint32_t Wheel(byte WheelPos);

@bko, the mentioned file a-rainbow.cpp might actually be the output file the wiring preprocessor produced from the .ino file and I've not found a way to add C file in Build. But the redeclaration errors and the missing String declaration suggest a file issue.
So this might bring us back to two seperate files containing setup()/loop().

@dcdenison, could you provide a screenshot of your Build window?

When I build your code as is with Build it's fine.

1 Like

Definitely using Build.

Is there an efficient way to grab a screenshot if itā€™s too long to fit on one screen?

Iā€™m attaching 3 screenshots, to capture the whole magilla.



And this code in that project produces these errors :confused:

Could you check what target (device and system version) youā€™ve selected?
When I compile that code targeted at Core 0.5.2, I get exactly zero errors.


Hold a sec! It wasnā€™t exactly the same code. I missed the two includes at the top when I copied your code from above.
Once I added the #include "application.h" I got the same errors.

Just remove that line and try again - the preprocessor seems to play some tricks on you

you got it!

thanks.

I wonder where that came from?

2 Likes

[UPDATE]

Hi, added BulldogLowellā€™s code, above. Worked great. Very cool. Thanks!

Rainbow and Black worked perfectly.

Only one function stumped us: chase. One of the classic NeoPixel moves. We tried a lot of variations, but were just not able to get those pixels to chase each other around the ring. : )

Code below, any suggestions appreciated.

void chase(uint8_t wait)
{
  static int lastUpdateMillis = 0;
  static int direction = -1;
  static int pixelIndex = 0;
  if (millis() - lastUpdateMillis >= wait)
  {
    if (pixelIndex <= 0 or pixelIndex >= 255)
    {
      direction *= -1;
    }
    pixelIndex += direction;
    for (int i = 0; i < strip.numPixels(); i++)
    {
      if (pixelIndex = i)
      {
        strip.setPixelColor(i, 255, 255, 255);
      }
      else
      {
        strip.setPixelColor(i, 0, 0, 0);
      }   
    }
    strip.show();
    lastUpdateMillis = millis();
    pixelIndex++;
    
  }
}

Next Iā€™m going to hook it up to a javascript form to control it remotely. Iā€™ll share the code when I get it working.

Thanks again for all the help.

DC

if (pixelIndex = i)

try

if (pixelIndex == i)  // a lot more useful in making comparisons than the single "="

tsk tsk tskā€¦

fire your developer, immediately!

Hey thanks. Canā€™t wait to try it.

Whatā€™s the use of having NeoPixels if you canā€™t make them ā€œchaseā€?

Thanks again for upping the fun on this project : )

you have to get rid of this dopey line too:

pixelIndex++;

so, try this:

void chase(uint8_t wait)
{
  static int lastUpdateMillis = 0;
  static int direction = -1;
  static int pixelIndex = 0;
  if (millis() - lastUpdateMillis >= wait)
  {
    if (pixelIndex <= 0 or pixelIndex >= strip.numPixels())
    {
      direction *= -1;
    }
    pixelIndex += direction;
    for (int i = 0; i < 254 strip.numPixels(); i++)
    {
      if (pixelIndex == i)
      {
        strip.setPixelColor(i, 255, 255, 255);
      }
      else
      {
        strip.setPixelColor(i, 0, 0, 0);
      }   
    }
    strip.show();
    lastUpdateMillis = millis();
  }
}

and see what happensā€¦

sorry 'bout that :flushed:

Get ready NeoPixel, the chase is on! (once I flash this code).

Thanks BulldogLowell!

DC

1 Like

Thanks for everyone for helping out here!

If you want to see a giant project for NeoPixels that has an android and iOS app as well for example and control purposes, checkout Spark Pixels

1 Like