Loop glitch?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Stuie_K
 
Posts: 23
Joined: Sun Nov 30, 2014 12:31 pm

Loop glitch?

Post by Stuie_K »

Hello everyone,

Am starting to get my head around the code for neopixels,
I'm using an Arduino uno R3 on a Windows 7 laptop running the 1.5.8 version from arduino ,
Iv'e been tinkering with the variables on the colorWipe & theaterChase sections of the neopixel strandtest,
so far have only been able to change the color variables and speed of the colorWipe & theaterChase the rest still baffles me at the moment,
code verifies and uploads,the parts iv'e changed work perfectly,at most going through 48 different colorWipe & theaterChase sections,which looks really cool when you decrease the time for each colors rotation,
however,
The problem iv'e been getting occurs later in the sequence ,
The cycle starts itself again before it's had a chance to finish,
Sometimes missing out the last 2 aspects of the strandtest sequence altogether.
When this happens it's not always in the same position in the sequence when it decides to restart prematurely,
Iv'e tried unplugging,resetting and re-uploading the code and the problem persists,
It doesn't happen on the original strandtest code only on the ones iv'e modified,yet they load without error,
Is it a case of information overload ??(even though the sketches only use 11=12%)
Should i keep code sequences minimal to avoid uno memory confusion?
or is there a better arduino available?
Thanks in advance :)

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: Loop glitch?

Post by Franklin97355 »

If you would post your code perhaps we could find something to correct.

User avatar
Stuie_K
 
Posts: 23
Joined: Sun Nov 30, 2014 12:31 pm

Re: Loop glitch?

Post by Stuie_K »

this is baffling me,
iv'e only added extra color cycles in the first and second parts,and maybe changed some numbers further down,
but the glitch persists
here's the code (no laughing please)

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, 6, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

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

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(255, 0,115), 47); // Green
  colorWipe(strip.Color(187, 0,255), 44); // Blue
  colorWipe(strip.Color(98, 0,255), 41); 
  colorWipe(strip.Color( 4, 0,255), 38);
  colorWipe(strip.Color( 0,128,255), 35);
  colorWipe(strip.Color( 0,255,217), 32);
  colorWipe(strip.Color( 0,255,77), 29);
  colorWipe(strip.Color( 0,255, 0), 26);
  colorWipe(strip.Color(251,255, 0), 23);
  colorWipe(strip.Color(255,119, 0), 20);
  colorWipe(strip.Color(255, 0, 0), 17);
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 20); // White
  theaterChase(strip.Color(127, 0, 0), 23); // Red
  theaterChase(strip.Color(0,127, 0), 26); // Green
  theaterChase(strip.Color( 0, 0,125), 29); // Blue
  theaterChase(strip.Color(100,100,100), 32); // White
  theaterChase(strip.Color(200, 0, 0), 35); // Red
  theaterChase(strip.Color(204,255, 0), 38); // Neon Yellow
  theaterChase(strip.Color(57,255,20), 41); // Neon Green
  theaterChase(strip.Color(0, 0,237), 43); // Deep Blue
  theaterChase(strip.Color(0,184,184), 46); // Aqua
  theaterChase(strip.Color(187, 0,255), 49); // Purple
  theaterChase(strip.Color(255,10,133), 51); // Bright Pink
  
  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();
     
      delay(wait);
     
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
        }
        strip.show();
       
        delay(wait);
       
        for (int i=0; i < strip.numPixels(); i=i+3) {
          strip.setPixelColor(i+q, 0);        //turn every third pixel off
        }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}
Last edited by Franklin97355 on Sun Dec 14, 2014 8:17 pm, edited 1 time in total.
Reason: Added missing [code] tags.

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

Return to “Arduino”