neopixel code issue


hi all
im trying make "fancy" light go on flag pole when camping in caravan.  im testing using 1m 30led strip , want create different patterns , randomise them.  have patterns done strandtest code few changes here , there.  i've seen code on adafruits site looks light knight rider , have code fast led library led goes 1 way bounces back. when reaches start changes colour , repeats. want colour change on knight rider type 1 cant work.

if has other cool patterns not mind sharing good.  going 5 meter strip in end.

this adafruit code.
code: [select]
#include <adafruit_neopixel.h>

#define n_leds 30
#define pin     6

adafruit_neopixel strip = adafruit_neopixel(n_leds, pin, neo_grb + neo_khz800);

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

int pos = 0, dir = 1; // position, direction of "eye"

void loop() {
  int j;

  // draw 5 pixels centered on pos.  setpixelcolor() clip any
  // pixels off ends of strip, don't need watch that.
 
  //strip.setpixelcolor(pos - 2, 16,0,0); // dark red
  //strip.setpixelcolor(pos - 1, 128,0,0); // medium red
  //strip.setpixelcolor(pos    , 255,48,0); // center pixel brightest
  //strip.setpixelcolor(pos - 1, 128,0,0); // medium red
  //strip.setpixelcolor(pos - 2, 16,0,0); // dark red
 
  //strip.setpixelcolor(pos - 2, 255,10,0); // dark red
  //strip.setpixelcolor(pos - 1, 0,255,0); // medium red
  //strip.setpixelcolor(pos    , 0,150,255); // center pixel brightest
  //strip.setpixelcolor(pos - 1, 0,255,0); // medium red
  //strip.setpixelcolor(pos - 2, 255,10,0); // dark red
 
  strip.setpixelcolor(pos - 2, 0x100000); // dark red
  strip.setpixelcolor(pos - 1, 0x800000); // medium red
  strip.setpixelcolor(pos    , 0xff3000); // center pixel brightest
  strip.setpixelcolor(pos + 1, 0x800000); // medium red
  strip.setpixelcolor(pos + 2, 0x100000); // dark red

  strip.show();
  delay(30);

  // rather being sneaky , erasing tail pixel,
  // it's easier erase , draw new 1 next time.
  for(j=-2; j<= 2; j++) strip.setpixelcolor(pos+j, 0);

  // bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numpixels()) {
    pos = strip.numpixels() - 2;
    dir = -dir;
  }
}


this led bounce code.

code: [select]
    #include <fastled.h>
    #define num_leds 30
    #define data_pin 6
   
crgb leds[num_leds];

   void setup() {
       fastled.addleds<neopixel, data_pin>(leds, num_leds);
   }
   
void loop() {
// first slide led in 1 direction
for(int = 0; < num_leds; i++) {
// set i'th led red
leds[i] = crgb::red;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}

// go in other direction. 
for(int = num_leds-1; >= 0; i--) {
// set i'th led red
leds[i] = crgb::red;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}

// first slide led in 1 direction
for(int = 0; < num_leds; i++) {
// set i'th led red
leds[i] = crgb::green;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}

// go in other direction. 
for(int = num_leds-1; >= 0; i--) {
// set i'th led red
leds[i] = crgb::green;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}

// first slide led in 1 direction
for(int = 0; < num_leds; i++) {
// set i'th led red
leds[i] = crgb::blue;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}

// go in other direction. 
for(int = num_leds-1; >= 0; i--) {
// set i'th led red
leds[i] = crgb::blue;
// show leds
fastled.show();
// we've shown leds, reset i'th led black
leds[i] = crgb::black;
// wait little bit before loop around , again
delay(30);
}
}


thanks
lee

a little bit more information on want please.


Arduino Forum > Using Arduino > LEDs and Multiplexing > neopixel code issue


arduino

Comments