"Growing" pixels with Neopixel Strip

So I just received my 60 led Neopixel Strip, and I’ve been messing around with the code. I’m not too familiar with the Neopixel library, so I was wondering if you guys might be able to help me out. What I’m trying to do, is have 4 pixels constantly lit in the center of the strip and 2 pixels constantly lit on either end of the strip. Using a potentiometer, I want to be able to make the center strip increase in size out to either end of the strip. I’ve found a piece of code on the internet that bounces a led segment back and fourth between the two ends of the strip. I figured this would be a good place to start. I just have to figure out how to make the segment stationary at the start, then be able to build towards the ends. This should be an easy fix, but I haven’t played with Arduino in a little while and I’m not sure where to go from here.

//NeoPixel LED Digital Strip Cylon Eye v1.10 Created by EternalCore
#include <Adafruit_NeoPixel.h>

//Settings:
#define PIN 6 //The Pin out your Neopixel DIN strip/stick is connected to (Default is 6)
#define TPIXEL 60 //The total amount of pixel's/led's in your connected strip/stick (Default is 60)
int wait_T=40; //This is the delay between moving back and forth and per pixel
int PixelCount=60; //Set this to the AMOUNT of Led's/Pixels you have or want to use on your strip And It can be used to tell where to Stop then return the eye at in the strip
int Pixel_Start_End=0; //Set this to where you want it to Start/End at
boolean UsingBar = false; //Set this to true If you are using the 8x1 Neopixel Bar Or you want to only use 3 leds for the scanner. 

Adafruit_NeoPixel strip = Adafruit_NeoPixel(TPIXEL, PIN, NEO_GRB + NEO_KHZ800); //Standered Strip function

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  //Serial.begin(9600); //Used For pixel Count Debugging
}
void loop() {
  //Example: CylonEyeUp(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeUp(strip.Color(175,0,0), strip.Color(25,0,0), strip.Color(10,0,0), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
  //Example: CylonEyeDown(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeDown(strip.Color(175,0,0), strip.Color(25,0,0), strip.Color(10,0,0), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
}

void CylonEyeUp(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pStart) {
  for(int i=pStart; i<TotalPixels; i++) {
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color
    strip.setPixelColor(i+1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);     //Center Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color

    if(!UsingBar) {
      strip.setPixelColor(i-3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i-2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}
void CylonEyeDown(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pEnd) {
  for(int i=TotalPixels-1; i>pEnd; i--) {
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);    //Center Dot Color
    strip.setPixelColor(i+1, Ct);  //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color

    if(!UsingBar) { 
      strip.setPixelColor(i+3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i+2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}

Any thoughts? Thanks!

Any thoughts? Thanks!

It looks to me like strip.setPixelColor(i, Co); sets the color of the ith pixel. It should be trivial to determine the value of i, based on the number of pixels in your strip, so that you can set whichever pixels you like on or off or whatever color you like.

PaulS:

Any thoughts? Thanks!

It looks to me like strip.setPixelColor(i, Co); sets the color of the ith pixel. It should be trivial to determine the value of i, based on the number of pixels in your strip, so that you can set whichever pixels you like on or off or whatever color you like.

This actually helps alot! Although, I do not know what Co is. I've got my middle and end LED's constantly lit, now I have to figure out how I would go about adding and subtracting LEDs when I spin the pot. Hmm.

WeAreTheMusicMakers: This actually helps alot! Although, I do not know what Co is. I've got my middle and end LED's constantly lit, now I have to figure out how I would go about adding and subtracting LEDs when I spin the pot. Hmm.

Co is the color and brightness you want to set it to. You can call setPixelColor with 4 arguments or 2. If it is 4 arguments, the first argument is the pixel number, and the remaining 3 arguments are red, green, and blue. For red, green, and blue the value is from 0 (off) to 255 (max brightness). So:

  • setPixelColor (10, 0, 0, 0); // turn off pixel completely.
  • setPixelColor (10, 10, 0, 0); // turn on red to brightness level 10, blue/green off.
  • setPixelColor (10, 25, 25, 25); // turn all 3 pixels on to the same brightness which gives white.

The 2 argument form combines the red, green, and blue colors into one unsigned long. You must declare the values as unsigned long, since on an AVR Arduino, an int is only 16-bits, and you need 24-bits to represent the colors.

  • setPixelColor (10, 0x000000UL); // turn off pixel completely.
  • setPixelColor (10, 0x0A0000UL); // turn on red to brightness level 10, blue/green off.
  • setPixelColor (10, 0x191919UL); // turn all 3 pixels on to the same brightness (25) which gives white.