help with compile error

Hi
I have started putting together a project to rotate through different light patterns using the adafruit lib. I had it working and wanted to add the below code which is using the same lib but get these errors.
Can any one help me understand why. I think i’ve got everything in the correct places.

Build options changed, rebuilding all
Full-not-working.ino:10:1: error: stray ‘’ in program
Full-not-working.ino:10:1: error: stray ‘’ in program
Full-not-working.ino:10:3: error: ‘Ripple’ does not name a type
Full-not-working.ino: In function ‘void loop()’:
Full-not-working.ino:51:12: error: too many arguments to function ‘void ripple()’
Full-not-working.ino:16:6: note: declared here
Full-not-working.ino: In function ‘void ripple()’:
Full-not-working.ino:147:5: error: ‘color’ was not declared in this scope
Full-not-working.ino:154:40: error: ‘color’ was not declared in this scope
Full-not-working.ino:159:55: error: ‘color’ was not declared in this scope
Error compiling.

My code is attached as not working including ripple code.txt

Original code that works (from NeoPixel Ripple · GitHub) working ripple effect.txt
I’ve had to attach as it said I was over the 9000 characters

advice much appreciated
Thanks

not working including ripple code.txt (5.48 KB)

Working ripple effect.txt (2.9 KB)

\Ripple

//Ripple
Line 10
:wink:

LarryD
Thanks. you know how it is, you look for so long you go blind to it. :slight_smile:
Im still getting this though which is for   ripple(50); //ripple
Full-not-working.ino: In function 'void loop()':
Full-not-working.ino:51:12: error: too many arguments to function 'void ripple()'
Full-not-working.ino:16:6: note: declared here
Error compiling.

Am I right in thinking the number in brackets is number of times to repeat? I took 50 out and its compiles but I only want it to run for a min or 2 then move on to next. works in all the others.
Thanks

Am I right in thinking the number in brackets is number of times to repeat?

No.

Full-not-working.ino:51:12: error: too many arguments to function ‘void ripple()’

When you define the function ripple you do not have any arguments in it. However when you call the function ripple you are attempting to pass one argument to it, the value 50. That is more than the compiler is expecting. So ether remove the number you are passing to the ripple function or define that the ripple function takes in one variable.

Hi Mike
I have picked at it and got it to compile but as in the code below it runs the 2 colorwipe’s then flickers and does the rainbow and repeats. Its trying but only displays for a fraction on a second. I would like to figure it out but am stuck knowing what parts do. for example in the colorwipe I can change values and its makes it run faster/slower etc but what does each bit do. I read what the uint8 and 32 are but how and what they are doing in this i dont know.

The below section uint32 has a c and uint8 says wait. under delay it says wait but for what and how long. I have other project with wait and changing the value changes the speed. Sorry for all the question but tying to google how a bit of code works does not work. Can get what uint32 is but not in the context of the code.

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);
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define Pixels 30  // ripple
#define BG 1 //ripple


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

//Ripple
int color;
int center = 0;
int step = -1;
int maxSteps = 16;
float fadeRate = 0.6;
int diff;
 
//background color
uint32_t currentBg = random(256);
uint32_t nextBg = currentBg;
//ripple end

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

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(22, 255, 235), 25); // Light Blue
  colorWipe(strip.Color(182, 3, 255), 25); // purple
  ripple(20); //ripple
 rainbow(20);
  
}
 
// 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*5; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

void ripple(uint32_t wait) {
  if (BG){
    if (currentBg == nextBg) {
      nextBg = random(256);
    } 
    else if (nextBg > currentBg) {
      currentBg++;
    } else {
      currentBg--;
    }
    for(uint16_t l = 0; l < Pixels; l++) {
      strip.setPixelColor(l, Wheel2(currentBg, 0.1));
    }
  } else {
    for(uint16_t l = 0; l < Pixels; l++) {
      strip.setPixelColor(l, 0, 0, 0);
    }
  }
 
 
  if (step == -1) {
    center = random(Pixels);
    color = random(256);
    step = 0;
  }
 
 
 
  if (step == 0) {
    strip.setPixelColor(center, Wheel2(color, 1));
    step ++;
  } 
  else {
    if (step < maxSteps) {
      strip.setPixelColor(wrap(center + step), Wheel2(color, pow(fadeRate, step)));
      strip.setPixelColor(wrap(center - step), Wheel2(color, pow(fadeRate, step)));
      if (step > 3) {
        strip.setPixelColor(wrap(center + step - 3), Wheel2(color, pow(fadeRate, step - 2)));
        strip.setPixelColor(wrap(center - step + 3), Wheel2(color, pow(fadeRate, step - 2)));
      }
      step ++;
    } 
    else {
      step = -1;
    }
  }
  
  strip.show();
  delay(50);
}
 
 
int wrap(int step) {
  if(step < 0) return Pixels + step;
  if(step > Pixels - 1) return step - Pixels;
  return step;
}
 
 
 
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel2(byte Wheel2Pos, float opacity) {
  
  if(Wheel2Pos < 85) {
    return strip.Color((Wheel2Pos * 3) * opacity, (255 - Wheel2Pos * 3) * opacity, 0);
  } 
  else if(Wheel2Pos < 170) {
    Wheel2Pos -= 85;
    return strip.Color((255 - Wheel2Pos * 3) * opacity, 0, (Wheel2Pos * 3) * opacity);
  } 
  else {
    Wheel2Pos -= 170;
    return strip.Color(0, (Wheel2Pos * 3) * opacity, (255 - Wheel2Pos * 3) * opacity);
  }
}
//ripple end



// 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) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Many thanks

A uint32 is an unsigned integer variable that is 32 bits long.

uint8 says wait. under delay it says wait but for what and how long.

Wait for time to pass. For as many milliseconds as are contained in the variable you pass to it. So when you call that function and pass it a number (between 0 and 255 because it is only a single byte ) then the code will do nothing at that point for that many milliseconds.

So the colorWipe function sets all the pixels to the same colour, displays it, and halts any further code running for a number of milliseconds.

Grumpy_Mike:
If you draw out each bit in this 32 bit variable and label each bit from right to left 0 to 31 then the bits have the following meaning.
Bits 0 to 4 define the amount of blue in the colour
Bits 5 to 10 define the amount of green in the colour
Bits 6 to 15 define the amount of red in the colour

So only 16 of the 32 bits are used? 5 bits for blue and 6 bits each for red & green? Why did they not use 8 bits for each channel? Or use a 16 bit integer and save 4 bytes?

I thought ws2812 leds had 8-bit pwm for each channel, and there would be room in a 32-bit variable to hold that in full. Is the neopixel library not giving us access to the ws2812's full pwm accuracy?

Paul

Sorry that information was about the OLED colour display not the neopixel. I have been doing a lot of the OLED stuff lately for this project:-

Edited that reply to remove the erroneous information.

In fact the neopixel has a function to concatenate the RGB bytes into a colour variable
it is the .Color class, that takes in three bytes so the .setPixelColor class take is a position and a colour variable produced by the .Color class.
So combining the two as an example:-

colorWipe(strip.Color(r,g,b), 50));

Will fill all the pixels with a colour generated by the three bytes r,g,b and hold that display for 50mS.

Of the bytes in the uint32_t only 24 of them are needed.
Note that with the through hole LEDs as opposed to the surface mount ones the .Color class is defined as :-
strip.Color(g,r,b)

Thanks guys.
I got it to compile but the ripple function only shows for a fraction of a second and moved onto the next.
Someone has told me of a rewrite of a lot of the code im using and the format has changed a lot so im going to have a good read of the doc for that and see if I can get it working on that.
Thanks again

If the ripple effect does no go on long enough then just call that function many times in a for loop.