Neopixel code help needed


i starting play around neopixels , trying own coding down.  mind not means programmer, methods pretty basic.

also ignore rgb values.  reason lights have switched around standard rgb or grb.  operate using rbg...??? 

for first program want have 4 colors each 10 pixels long chasing each other.  these 4 colors repeat throughout whole strand.

this code not work.  colors overlapping, , lose bunch of red segments.

code: [select]
#include <adafruit_neopixel.h>
#ifdef __avr__
  #include <avr/power.h>
#endif

#define pin 6

// parameter 1 = number of pixels in strip
// parameter 2 = arduino pin number (most valid)
// parameter 3 = pixel type flags, add needed:
//   neo_khz800  800 khz bitstream (most neopixel products w/ws2812 leds)
//   neo_khz400  400 khz (classic 'v1' (not v2) flora pixels, ws2811 drivers)
//   neo_grb     pixels wired grb bitstream (most neopixel products)
//   neo_rgb     pixels wired rgb bitstream (v1 flora pixels, not v2)
adafruit_neopixel strip = adafruit_neopixel(100, pin, neo_grb + neo_khz800);

// important: reduce neopixel burnout risk, add 1000 uf capacitor across
// pixel power leads, add 300 - 500 ohm resistor on first pixel's data input
// , minimize distance between arduino , first pixel.  avoid connecting
// on live circuit...if must, connect gnd first.

  uint32_t red = strip.color(255, 0, 0);
  uint32_t blue = strip.color(0, 255, 0);
  uint32_t lime = strip.color(0, 0, 255);
  uint32_t magenta = strip.color(255, 255, 0);
  uint32_t teal = strip.color(0, 255, 255);
  uint32_t yellow = strip.color(255, 0, 255);
  uint32_t white = strip.color(255, 255, 255);
  uint32_t orange = strip.color(255, 0, 128);
  uint32_t pink = strip.color(255, 203, 192);
  uint32_t purple = strip.color(128, 128, 0);
  uint32_t green = strip.color(0, 0, 128);
  uint32_t brown = strip.color(165, 42, 42);
  uint32_t maroon = strip.color(128, 0, 0);
  int r = 0;
  int g = 10;
  int w = 20;
  int b = 30;

void setup() {
  strip.begin();
  strip.show(); // initialize pixels 'off'
}

void loop() {
 strip.setpixelcolor(r, red);
 strip.setpixelcolor(r+40, red);
 strip.setpixelcolor(r+80, red);
 strip.setpixelcolor(r-40, red);
 strip.setpixelcolor(r-80, red);
 strip.setpixelcolor(g, lime);
 strip.setpixelcolor(g+40, lime);
 strip.setpixelcolor(g+80, lime);
 strip.setpixelcolor(g-40, lime);
 strip.setpixelcolor(g-80, lime);
 strip.setpixelcolor(w, white);
 strip.setpixelcolor(w+40, white);
 strip.setpixelcolor(w+80, white);
 strip.setpixelcolor(w-40, white);
 strip.setpixelcolor(w-80, white);
 strip.setpixelcolor(b, blue);
 strip.setpixelcolor(b+40, blue);
 strip.setpixelcolor(b+80, blue);
 strip.setpixelcolor(b-40, blue);
 strip.setpixelcolor(b-80, blue);
 strip.show();
 r++;
 g++;
 w++;
 b++;
 if (r==strip.numpixels())r=0;
 if (g==strip.numpixels())g=0;
 if (w==strip.numpixels())w=0;
 if (b==strip.numpixels())b=0;
 delay(50);
}

program has problem, hope program can you.
code: [select]
#include <adafruit_neopixel.h>
 
#define pin 6
#define max_led 100

// parameter 1 = ws2811
// parameter 2 = arduino pin
// parameter 3 = pixel type flags, add needed:
// neo_khz800 800 khz bitstream (most neopixel products w/ws2812 leds)
// neo_khz400 400 khz (classic 'v1' (not v2) flora pixels, ws2811 drivers)
// neo_grb pixels wired grb bitstream (most neopixel products)
// neo_rgb pixels wired rgb bitstream (v1 flora pixels, not v2)
adafruit_neopixel strip = adafruit_neopixel( max_led, pin, neo_rgb + neo_khz800 );

uint8_t r[10]={0,100,160,255,16,200,78,49,60,43};
uint8_t g[10]={0,0,143,69,85,49,98,200,100,13};
uint8_t b[10]={255,100,69,100,200,50,0,0,255,255};


void setup()
{
  strip.begin();
  strip.show();
}

void loop()
{
  uint8_t i;

  for(i=0;i<10;i++)
  {
     strip.setpixelcolor(i,r[i],g[i],b[i]);
   }
   strip.show();
}


Arduino Forum > Using Arduino > LEDs and Multiplexing > Neopixel code help needed


arduino

Comments