0

fill a strip one pixel at a time
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

fill a strip one pixel at a time

by Joe36 on Sun Nov 19, 2017 9:39 pm

Hello I have a small strip (16) of pixels that I am trying to fill up one pixel at a time. I have been messing with this for a bit but I am very poor at coding. I am not looking for the colorwipe but to lite only one pixel and push it down the strip and stop lit at the end then do the same to the next position and so on till the strip is full then change to the next color and do the same thing. So far I have the below code that stops the led at the end of the strip, but I cant figure out how to do this from here. Thank you for any help.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define numpixels 16

Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
}
 
void loop() {
  chase(strip.Color(25, 0, 0)); // Red
  chase(strip.Color(0, 25, 0)); // Green
  chase(strip.Color(0, 0, 25)); // Blue
}
 
void chase(uint32_t c) {

     for(int i = 0; i < numpixels; i++) {
      strip.setPixelColor(i  , c); // Draw new pixel
      strip.setPixelColor(i-1, 0); // Erase pixel a few steps back

      strip.show();
      delay(85);
  }
}

Joe36
 
Posts: 16
Joined: Tue Dec 27, 2016 10:36 am

Re: fill a strip one pixel at a time

by franklin97355 on Sun Nov 19, 2017 11:22 pm

What happens when you run your code? If you decrement the number of pixels every time you finish your loop what happens?

franklin97355
 
Posts: 17078
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: fill a strip one pixel at a time

by Joe36 on Mon Nov 20, 2017 10:35 am

Currently it runs a single pixel down the strip and stops leaving the last pixel lit till the loop runs the next color.

Joe36
 
Posts: 16
Joined: Tue Dec 27, 2016 10:36 am

Re: fill a strip one pixel at a time

by kcl1s on Mon Nov 20, 2017 12:25 pm

As Franklin say you need to subtract a pixel and run the loop until it is full. You do this by Nesting two for loops inside one another. You already have the inside loop you will just need to change from numpixels to the counter variable from the outside loop. Your outside loop will be a decreasing counter for loop that goes from numpixels-1 to >=0. Give it a try and post your code if you have trouble.
format like this
Code: Select all | TOGGLE FULL SIZE
  for outer loop {
    for inner loop {
      pixel code here
    }
  }


Keith

kcl1s
 
Posts: 466
Joined: Tue Aug 30, 2016 12:06 pm

Re: fill a strip one pixel at a time

by Joe36 on Thu Nov 30, 2017 7:39 pm

I'm going to be honest and say I have no idea how to do that. I probably shouldn't even be asking these questions as so far the only things I can get the led's to do is what I have cut and pasted in from other sketches I have found in other forums tutorials etc. My math is not even that good so its a major struggle for me.

Joe36
 
Posts: 16
Joined: Tue Dec 27, 2016 10:36 am

Re: fill a strip one pixel at a time

by kcl1s on Fri Dec 01, 2017 1:09 am

Copying others code is fine. The hard part is learning why they coded it that way. Loops are a basic building block for all code and coding languages. Having an understanding of loops along with variables, conditionals (if, else) and functions will make the learning easier. I am a volunteer tech teacher at several public libraries in my area. One of the best ways I have found to teach coding basics is code.org. I use their Express Course in my 12 hr Intro to programming course. https://studio.code.org/s/express It uses animations and block like code so you learn without having to have every comma, bracket and semi colon just right. I started teaching teens with this but find the adults love it too. If you work your way through this course you will be better prepared to tackle the Arduino.

Keith

EDIT Don't forget to signup for the free account so it saves your progress

kcl1s
 
Posts: 466
Joined: Tue Aug 30, 2016 12:06 pm

Please be positive and constructive with your questions and comments.