neopixel with button strobo

Hello

Can someone help with good working code?
I have made 2 x 9 rgb smd pixel boxes with adafruit NeonPixel but i don't know what i doing wrong, i don't understand not everything about the code, i think there something wrong with the the delay.

let me explane what it must be do.

al the time it must be change from alle leds red, to blue to yellow in a loop.
but when i press the button the leds are must be blinking like a strobo scoop with white leds color.
when i unpressed the button it must stop the stroboscoop and go furthe with the loop red, blue, yellow.

what it now does is hold on the button and the leds are white when its at the end of the yellow loop.

this is what i have made:

#include <Adafruit_NeoPixel.h>

//define colors
#define green 0,128,0
#define red 255,0,0
#define yellow 255,255,0
#define white 255,255,255

// define the input of smart neopixel rgb
#define PIN 6 

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

int buttonPin = 2;  // button pin variable
int buttonState = 0;         // current state of the button



void setup() 
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(buttonPin, INPUT); // set button pin to be an input
  digitalWrite(buttonPin,LOW);  // turn on Pull Up
}                      

void loop()
{

buttonState = digitalRead(buttonPin);

        if (buttonState == LOW) {
        colorWipe(strip.Color(white), 1);
        }
        else 
        {
                             


                     colorWipe(strip.Color(red), 1);
                     delay (1600); 

                     colorWipe(strip.Color(green), 1); 
                     delay (1600);

                     colorWipe(strip.Color(yellow), 1);
                     delay (1600);
                 }                         
                 } 



// Fill the RGB dots one after the other 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(2); //delay for color to change
  }
}

here a little picture:

thanks allot for helping

Can you see what changed?

#include <Adafruit_NeoPixel.h>

//define colors
#define green 0,128,0
#define red 255,0,0
#define yellow 255,255,0
#define white 255,255,255

// define the input of smart neopixel rgb
#define PIN 6

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

int buttonPin = 2;  // button pin variable
int buttonState = 0;         // current state of the button



void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(buttonPin, INPUT); // set button pin to be an input
  digitalWrite(buttonPin,HIGH);  // turn on Pull Up
}                     

void loop()
{

buttonState = digitalRead(buttonPin);

        if (buttonState == LOW) {
        colorWipe(strip.Color(white), 1);
        }
        else
        {
                             


                     colorWipe(strip.Color(red), 1);
                     delay (1600);

                     colorWipe(strip.Color(green), 1);
                     delay (1600);

                     colorWipe(strip.Color(yellow), 1);
                     delay (1600);
                 }                         
                 }



// Fill the RGB dots one after the other 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(2); //delay for color to change
  }
}

Yes

I see:

  digitalWrite(buttonPin,HIGH);  // turn on Pull Up

So, is that better?

Don't leave us in suspense! :grinning:

Yes its working but i mean something else,

Maybe my explanation is not so good, what I actually mean is, if I press the button, the withe leds must be flashes and when i unpress the button he must go further with red, blue yellow ect ect.

If i press the button now, hes first waiting till te last color has been light up (delay), but what ever the color is, red, blue or yellow, when i press the button he must directly flashing white color.

I hope this explanation is better, please let me know i men not understand it what i mean.

I have search the forum with word, break a delay ect but can't find a answer what i understand

Thanks alot for responsing.

Mars

I knew you would have that complaint!

Give me the rest of the day (have to go to work as it happens, these things do complicate matters) and I will sort it out. :grinning:

Unless anyone else does ...

Thanks alot :slight_smile:

Code tested.

#include <Adafruit_NeoPixel.h>

//define colors
#define green 0,128,0
#define red 255,0,0
#define yellow 255,255,0
#define white 255,255,255

// define the input of smart neopixel rgb
#define PIN 6

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

int buttonPin = 2;  // button pin variable
int buttonState = 0;         // current state of the button

// Fill the RGB dots one after the other 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(2); //delay for color to change
  }
}

boolean waitnotpress(int ticks)
{
  while (ticks-- >= 0) {
    buttonState = digitalRead(buttonPin);
    if (buttonState == LOW) return (false);
    delay(1);
  }
  return (true);
}

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(buttonPin, INPUT); // set button pin to be an input
  digitalWrite(buttonPin, HIGH); // turn on Pull Up
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    colorWipe(strip.Color(white), 1);
  }
  else
  {
    colorWipe(strip.Color(red), 1);
    if (waitnotpress(1600)) {

      colorWipe(strip.Color(green), 1);
      if (waitnotpress(1600)) {

        colorWipe(strip.Color(yellow), 1);
        if (waitnotpress(1600)) {
        }
      }
    }
  }
}

Hi Paul!

Thanks Thanks Thanks, its working!

Exactly what I want, I see now what different is witch I have build.
In the void loop() there is no delay and without that, de pushbutton is working fine and directly.

Thanks a lot!!!
Kind Regards Marcel

djdeeno:
In the void loop() there is no delay and without that, de pushbutton is working fine and directly.

Well, that is not quite true; there is a delay, but a very small one and it is called alternately with the button test.

That is the secret to real-time programming - you do not get hung up on any one item; you check each item of importance in turn and deal only with such things as can be performed immediately.

Hi

I have an other question about this fine working programm.
When i pressed the button, the strobo is working, but how can make a other pin on the arduino active.

So lets say pin 13, when i pressed button, the strobo wil be on and also pin 13 wil be HIGH, when i stop pressing the button, strobo stops, also pin 13 gonna be LOW and the normal leds are running again.

ps pin 13 stays on, its not flashing with the strobo when i pres the button.

Any idea?

Thanks again!!!