"Growing" pixels with Neopixel Strip

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
freakonaleash31
 
Posts: 1
Joined: Wed Dec 04, 2013 2:56 pm

"Growing" pixels with Neopixel Strip

Post by freakonaleash31 »

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.

Code: Select all

//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!

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

Re: "Growing" pixels with Neopixel Strip

Post by adafruit_support_bill »

[Moved to "Glowy Things"]

User avatar
fid
 
Posts: 74
Joined: Wed Sep 25, 2013 3:00 pm

Re: "Growing" pixels with Neopixel Strip

Post by fid »

Greets freakonaleash31,
Uh, let's see... I would test the potentiometer on the arduino with an analogRead on the pin you have it hooked to. You can print the reading out to the arduino sketch serial window. With the numbers you receive, highest and lowest, subtract to get the range. Divide the result by 25. 25 because half of the pixel strip is 30. There are two pixels on the end of the strip and two on the middle (end) of the strip with 26 pixels not lit, yet. When the potentiometer is at the lowest all 26 will be off. When the potentiometer is at the highest all of the 26 pixels will be lit.
Write code in your sketch that will read the pin the potentiometer is attached to. When the potentiometer starts to move turn on two of the pixels next to the ones in the center. One on either side of the always-on four pixels. When the potentiometer moves a little bit more, past the threshold into the second area of the range turn on two more pixels. When you move the potentiometer into the next section of the range add two more pixels away from the center.
The potentiometer will probably read from 0 to 1023. For 25 segments of that range you could increase the number of lit pixels in the center for every increase of 40 in the range that is read. A reading of 1 through 40 would increase the center lights by two. 41 through 80 would increase the lights by an additional two, and so on.
If you moved the potentiometer too quickly you could calculate how many to light up by dividing the reading by 40 and take the integer and add 1. A reading of 52 is in the second range. The integer of 52/40 is 1. Add 1 to show that it is in the second section.
To start you only have four pixels lit up in the center. They are 29 through 32. When the potentiometer is in section 1 you would need to light up 28 through 33. So, you would subtract the value of the range from 29 and add that same value to 32.
I hope this helps. If you want a better or more detailed explanation I can work that out tomorrow. -fid

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

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”