parameter object neopixel

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
e-nodev
 
Posts: 9
Joined: Thu Feb 27, 2014 5:03 am

parameter object neopixel

Post by e-nodev »

Hello,
I want to add a parameter in objects but my method does not work. Can you indicate me the good method?
See the test code.
Thank you.
BANNED

Code: Select all


#include <Adafruit_NeoPixel.h>

#define PIN3 3
#define PIN5 5
#define PIN6 6

Adafruit_NeoPixel stripA = Adafruit_NeoPixel(8, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripB = Adafruit_NeoPixel(8, PIN5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripC = Adafruit_NeoPixel(8, PIN6, NEO_GRB + NEO_KHZ800);

void setup()
{
  initSetup('stripA');
  initSetup('stripB');
  initSetup('stripC');
}

void loop()
{
  colorWipe(stripA.Color(20, 0, 0), 50, 'myStripA');
  colorWipe(stripB.Color(20, 0, 0), 50, 'myStripB');
  colorWipe(stripC.Color(20, 0, 0), 50, 'myStripC');  
}

void initSetup (char myStrip)
{  
  myStrip.begin();
  myStrip.show();
}

void colorWipe(uint32_t coulor, uint8_t wait, char myStrip)
{
  for(uint16_t i=0; i<myStrip.numPixels(); i++)
  {
      myStrip.setPixelColor(i, coulor);
      myStrip.show();
      delay(wait);
  }
}


User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: parameter object neopixel

Post by adafruit_support_bill »

You have defined the parameter as a char, you are passing it a string and trying to use it as a Adafruit_NeoPixel.

It can't be three different types. You need to declare and use it as the same type: Adafruit_NeoPixel

Code: Select all


#include <Adafruit_NeoPixel.h>

#define PIN3 3
#define PIN5 5
#define PIN6 6

Adafruit_NeoPixel stripA = Adafruit_NeoPixel(8, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripB = Adafruit_NeoPixel(8, PIN5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripC = Adafruit_NeoPixel(8, PIN6, NEO_GRB + NEO_KHZ800);

void setup()
{
  initSetup(stripA);
  initSetup(stripB);
  initSetup(stripC);
}

void loop()
{
  colorWipe(stripA.Color(20, 0, 0), 50, stripA );
  colorWipe(stripB.Color(20, 0, 0), 50, stripB );
  colorWipe(stripC.Color(20, 0, 0), 50, stripC);  
}

void initSetup (Adafruit_NeoPixel myStrip)
{  
  myStrip.begin();
  myStrip.show();
}

void colorWipe(uint32_t coulor, uint8_t wait, Adafruit_NeoPixel myStrip)
{
  for(uint16_t i=0; i<myStrip.numPixels(); i++)
  {
      myStrip.setPixelColor(i, coulor);
      myStrip.show();
      delay(wait);
  }
}

User avatar
e-nodev
 
Posts: 9
Joined: Thu Feb 27, 2014 5:03 am

Re: parameter object neopixel

Post by e-nodev »

ok,
Thank you very much.
BANNED

User avatar
e-nodev
 
Posts: 9
Joined: Thu Feb 27, 2014 5:03 am

Re: parameter object neopixel

Post by e-nodev »

Hello,
I made a try with your code but it does not work. Nevertheless, there is not from the error to the compilation. Can you help me?
Thank you
BANNED

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: parameter object neopixel

Post by adafruit_support_bill »

Post the code you are using.

User avatar
e-nodev
 
Posts: 9
Joined: Thu Feb 27, 2014 5:03 am

Re: parameter object neopixel

Post by e-nodev »

Code: Select all


#include <Adafruit_NeoPixel.h>

#define PIN3 3
#define PIN5 5
#define PIN6 6

Adafruit_NeoPixel stripA = Adafruit_NeoPixel(8, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripB = Adafruit_NeoPixel(8, PIN5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripC = Adafruit_NeoPixel(8, PIN6, NEO_GRB + NEO_KHZ800);

void setup()
{
  initSetup(stripA);
  initSetup(stripB);
  initSetup(stripC);
}

void loop()
{
  colorWipe(stripA.Color(20, 0, 0), 50, stripA );
  colorWipe(stripB.Color(20, 0, 0), 50, stripB );
  colorWipe(stripC.Color(20, 0, 0), 50, stripC); 
}

void initSetup (Adafruit_NeoPixel myStrip)
{ 
  myStrip.begin();
  myStrip.show();
}

void colorWipe(uint32_t coulor, uint8_t wait, Adafruit_NeoPixel myStrip)
{
  for(uint16_t i=0; i<myStrip.numPixels(); i++)
  {
      myStrip.setPixelColor(i, coulor);
      myStrip.show();
      delay(wait);
  }
}


User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: parameter object neopixel

Post by adafruit_support_bill »

You probably need to pass those by reference (pointer actually) instead of by value. I don't have a setup to test here, but I think this should work.

Code: Select all


#include <Adafruit_NeoPixel.h>

#define PIN3 3
#define PIN5 5
#define PIN6 6

Adafruit_NeoPixel stripA = Adafruit_NeoPixel(8, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripB = Adafruit_NeoPixel(8, PIN5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripC = Adafruit_NeoPixel(8, PIN6, NEO_GRB + NEO_KHZ800);

void setup()
{
  initSetup(&stripA);
  initSetup(&stripB);
  initSetup(&stripC);
}

void loop()
{
  colorWipe(stripA.Color(20, 0, 0), 50, &stripA );
  colorWipe(stripB.Color(20, 0, 0), 50, &stripB );
  colorWipe(stripC.Color(20, 0, 0), 50, &stripC); 
}

void initSetup (Adafruit_NeoPixel* myStrip)
{ 
  myStrip->begin();
  myStrip->show();
}

void colorWipe(uint32_t coulor, uint8_t wait, Adafruit_NeoPixel* myStrip)
{
  for(uint16_t i=0; i<myStrip->numPixels(); i++)
  {
      myStrip->setPixelColor(i, coulor);
      myStrip->show();
      delay(wait);
  }
}


User avatar
e-nodev
 
Posts: 9
Joined: Thu Feb 27, 2014 5:03 am

Re: parameter object neopixel

Post by e-nodev »

It is good that works.
I have another question: how much meter of thread can he have between the arduino card(map) and the band(strip) of leds there?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: parameter object neopixel

Post by adafruit_support_bill »

You should try to keep the distance short. Less than a meter should be OK.
For longer distances, you may need to add some line drivers. People have had success with long runs of cat5 using RS485 drivers for the signal: viewtopic.php?f=47&t=49543&p=249621

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”