Go Down

Topic: Help with programing Neopixels to chase at different speeds (Read 297 times) previous topic - next topic

RatPackVegas

Oct 03, 2018, 06:15 pm Last Edit: Oct 04, 2018, 12:09 pm by RatPackVegas Reason: Adding Code
I have a project that I am working on which is basically a Theater Chase of Neopixels that transition from blue to red and back again along the same chase. It is one long string of 463 neopixels. Right now all the colors are chasing at the same "speed".  Is there a way to make the red Neopixel move at a faster "speed" than the blue one?  Any help would be appreciated, I am still new to programming.  My code is uploaded below.




Code: [Select]


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6

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


void setup() {


strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

void loop() {


theaterChase(100);

}


//Theatre-style crawling lights.
void theaterChase(int wait) {

  for (int q=0; q < 3; q++)                             //offset
  {
       for (int x=0; x < 90; x=x+3) {
         strip.setPixelColor(x+q, strip.Color(0,0,200));    //turn every third pixel on blue
                 }
        

       for (int y=93; y < 213; y=y+3) {
        strip.setPixelColor(y+q, strip.Color(200,0,0));    //turn every third pixel on red
         }

        
       for (int z=228; z < 231; z=z+3) {
         strip.setPixelColor(z+q, strip.Color(200,0,100));    //turn every third pixel on purple
         }

          
       for (int z=231; z < 281; z=z+3) {
         strip.setPixelColor(z+q, strip.Color(0,0,200));    //turn every third pixel on blue
         }
    
    
        for (int a=282; a < 285; a=a+3) {
         strip.setPixelColor(a+q, strip.Color(200,0,200));    //turn every third pixel on purple
         }
    

    
        for (int b=285; b < 355; b=b+3) {
         strip.setPixelColor(b+q, strip.Color(200,0,0));    //turn every third pixel on red
         }

        
        for (int b=366; b < 369; b=b+3) {
         strip.setPixelColor(b+q, strip.Color(200,0,0));    //turn every third pixel on red
         }

    
        for (int c=375; c < 406; c=c+3) {
         strip.setPixelColor(c+q, strip.Color(0,0,200));    //turn every third pixel on blue
         }
    

    
        for (int g=405; g < 410; g=g+3) {
         strip.setPixelColor(g+q, strip.Color(200,0,200));    //turn every third pixel on purple
         }
    

    
        for (int s=411; s < 462; s=s+3) {
         strip.setPixelColor(s+q, strip.Color(200,0,0));    //turn every third pixel on red
         }
  
     strip.show();

    delay(wait);

    for (int i=0; i < 463; i=i+3) {
      strip.setPixelColor(i+q, strip.Color(0,0,0));        //turn every third pixel off
      
    }
          
     }

}






      



 /code]


      



 

Paul__B

OK, let's cut to the chase.

Please go and read the instructions, then go back and modify your original post using the "More --> Modify" option you will find to the bottom right of the post, to mark up the code (but it always needs to be the complete code) as such so we can examine it conveniently and accurately.  Please do not post a ".ino" file as an attachment - that would mean that you are expecting people to actually load it to their IDE to look at it and that is extra unnecessary labour.  In fact, attachments do not always show properly on different operating systems.

If you do not mark it up as code, whatever code you do post could well be garbled and is certainly anything but easy to read.  Yours seems to have survived so far but I didn't look too closely.

Note: Also mark up any data - as a separate section - in the same way.  This includes error output that you get from the IDE.

And - before you post any code, use "Auto Format" in the Tools menu of the IDE to properly present the code.  You can then use the "copy for forum" function in order to paste it into a message with the "code" tags already provided.

Try and avoid unnecessary white space (blank lines).  You should only use these to separate functional blocks of code.

RatPackVegas


RatPackVegas

I was able to work out the code .

Here it is:

Code: [Select]
#include <Adafruit_NeoPixel.h>

#define PIXELSPIN1   6
#define PIXELSPIN2   9
#define NUMPIXELS1   300
#define NUMPIXELS2   300
#define CALIBRATIONTIME 20000

Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUMPIXELS1, PIXELSPIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(NUMPIXELS2, PIXELSPIN2, NEO_GRB + NEO_KHZ800);


unsigned long pixelsInterval1=225;  // timing for Blue
unsigned long pixelsInterval2=150;  // timing for Red


unsigned long theaterChase1PreviousMillis=0;
unsigned long theaterChase2PreviousMillis=0;

int theaterChaseQ = 0;


uint16_t currentPixel = 0;// what pixel are we operating on

void setup() {
  currentPixel = 0;
 
  pixels1.begin(); // This initializes the NeoPixel library.
  pixels1.show(); // This sends the updated pixel color to the hardware.

  pixels2.begin(); // This initializes the NeoPixel library.
  pixels2.show(); // This sends the updated pixel color to the hardware.
     
}

void loop () {
 
       
     
        if ((unsigned long)(millis() - theaterChase1PreviousMillis) >= pixelsInterval1) {
          theaterChase1PreviousMillis = millis();
          theaterChase1(pixels1.Color(0, 0, 200)); // Blue

        }
       
        if ((unsigned long)(millis() - theaterChase2PreviousMillis) >= pixelsInterval2) {
          theaterChase2PreviousMillis = millis();
          theaterChase2(pixels2.Color(200, 0, 0)); // Red

        }
     
       

}



//Theatre-style crawling lights Blue
void theaterChase1(uint32_t c) {
  for (int i=0; i < pixels1.numPixels(); i=i+3) {
      pixels1.setPixelColor(NUMPIXELS1 -(i+theaterChaseQ), c);    //turn every third pixel on
    }
    pixels1.show();
    for (int i=0; i < pixels1.numPixels(); i=i+3) {
      pixels1.setPixelColor(NUMPIXELS1 - (i+theaterChaseQ), 0);        //turn every third pixel off
    }
    theaterChaseQ++;
    if(theaterChaseQ >= 3) theaterChaseQ = 0;
}

//Theatre-style crawling lights Red
void theaterChase2(uint32_t c) {
  for (int i=0; i < pixels2.numPixels(); i=i+3) {
      pixels2.setPixelColor(NUMPIXELS2 -(i+theaterChaseQ), c);    //turn every third pixel on
    }
    pixels2.show();
    for (int i=0; i < pixels2.numPixels(); i=i+3) {
      pixels2.setPixelColor(NUMPIXELS2 -(i+theaterChaseQ), 0);        //turn every third pixel off
    }
    theaterChaseQ++;
    if(theaterChaseQ >= 3) theaterChaseQ = 0;
}

Go Up