Neopixel strip on and off

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Neopixel strip on and off

Post by robertd5 »

Hello,
I am working on creating a a table top display. There will be items on the table that will need to be illuminated by a NeoPixel Stick - 8 x WS2812 5050 RGB LED with Integrated Drivers. The LED strip will turn on for a 10-15 seconds then off. Then another LED strip will turn on and off to illuminate another product. I would like to have this sequence of lights be triggered with a PIR sensor.

I can't seem to get the code to compile. The error I am getting is;
FFA.ino: In function 'void loop()':
FFA:40: error: 'colorWipe' was not declared in this scope
FFA:46: error: expected initializer before 'for'
FFA:46: error: 'i' was not declared in this scope
FFA:46: error: expected `;' before ')' token


I am using Arduino Uno and I have run a simple test stand on the LED strip and they work great. I just would like to know how to turn them on for a 10-15 seconds and turn on another strip. First I would like to just get one strip to turn on when the PIR sensor detects motion.
Thanks for any help.
Bob



Code: Select all

/* PIR sensor that turns on a Strip of LED neo pixles
 
 */

# define PIN 3

#include <Adafruit_NeoPixel.h>

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

int pirPin = 2;

int led = 3;




void setup() {

  pinMode(pirPin, INPUT);

  pinMode(led, OUTPUT);

  Serial.begin(9600);

  strip.begin();

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

void loop() {

  if (digitalRead(pirPin) == HIGH)
  {
    Serial.println("MOVEMENT");
    digitalWrite(led, HIGH);
    colorWipe(strip.Color(127, 127, 127), 100); // fill the strip with all white
    strip.show(); // Initialize all pixels to 'off'
    
    
// 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();
    }
  }
  
  else
  {
    strip.show(); // Initialize all pixels to 'off'
    Serial.println("NO Movement");
    digitalWrite(led, LOW);

    delay(500);
  }


  }


User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel strip on and off

Post by adafruit_support_bill »

It looks like you pasted the colorWipe function into the middle of your loop function. You can't define a function within a function.

Move the colorWipe function to the end of your file - after the end of the loop function.

User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Re: Neopixel strip on and off

Post by robertd5 »

Thanks

Am I going about this the right way using a colorWipe?

I moved the colorWipe out of the loop.

Now I get the error
FFA.ino: In function 'void loop()':
FFA:55: error: a function-definition is not allowed here before '{' token
FFA:59: error: expected `}' at end of input

Thanks for the help

Code: Select all

/* PIR sensor that turns on a Strip of LED neo pixles
 
 */

# define PIN 3

#include <Adafruit_NeoPixel.h>

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

int pirPin = 2;

int led = 3;




void setup() {

  pinMode(pirPin, INPUT);

  pinMode(led, OUTPUT);

  Serial.begin(9600);

  strip.begin();

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

void loop() {

  if (digitalRead(pirPin) == HIGH)
  {
    Serial.println("MOVEMENT");
    digitalWrite(led, HIGH);
    strip.show(); // Initialize all pixels to 'off'
    colorWipe(strip.Color(127, 127, 127),100); // fill the strip with all white
    
  }
  
  else
  {
    strip.show(); // Initialize all pixels to 'off'
    Serial.println("NO Movement");
    digitalWrite(led, LOW);

    delay(500);
  }
  
// 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();
  }


User avatar
davidl13
 
Posts: 187
Joined: Fri Oct 25, 2013 10:51 pm

Re: Neopixel strip on and off

Post by davidl13 »

First reading: At the very least, your "void loop() {" needs a closing "}".

User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Re: Neopixel strip on and off

Post by robertd5 »

Thanks
Added the "}"

Now I am getting the error
FFA.ino: In function 'void colorWipe(uint32_t, uint8_t)':
FFA:58: error: expected `(' before 'uint16_t'
FFA:58: error: 'i' was not declared in this scope

Code: Select all

/* PIR sensor that turns on a Strip of LED neo pixles
 
 */

# define PIN 3

#include <Adafruit_NeoPixel.h>

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

int pirPin = 2;

int led = 3;




void setup() {

  pinMode(pirPin, INPUT);

  pinMode(led, OUTPUT);

  Serial.begin(9600);

  strip.begin();

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

void loop() {

  if (digitalRead(pirPin) == HIGH)
  {
    Serial.println("MOVEMENT");
    digitalWrite(led, HIGH);
    strip.show(); // Initialize all pixels to 'off'
    colorWipe(strip.Color(127, 127, 127),100); // fill the strip with all white
    
  }
  
  else
  {
    strip.show(); // Initialize all pixels to 'off'
    Serial.println("NO Movement");
    digitalWrite(led, LOW);

    delay(500);
  }
  
}  
  
// 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();
  }

User avatar
davidl13
 
Posts: 187
Joined: Fri Oct 25, 2013 10:51 pm

Re: Neopixel strip on and off

Post by davidl13 »

First I'd suggest finding some programming tutorials to help you get a better understanding of the language.

Secondly, compare your current colorWipe()'s for() to the one you posted initially - see the difference? The compilation errors should be more clear now.

User avatar
bcochran1
 
Posts: 497
Joined: Mon Jan 21, 2013 10:46 pm

Re: Neopixel strip on and off

Post by bcochran1 »


davidl13 wrote:First I'd suggest finding some programming tutorials to help you get a better understanding of the language.


Yes, I want to agree with davidl13. +1.

With that said, all of programming is try, try, try again. Just like life. Learn about the language and keep on trying. You will get the hang of it and succeed in the end.

Bob


User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Re: Neopixel strip on and off

Post by robertd5 »

OK
Thanks for the encouragement,
I have done some more research on multiple Neopixel objects on unique pins and have come up with a new approach.
As you may recall, I am trying to illuminate 3 different Neopixels sticks in a sequence and not all at the same time.

I almost have it working. The first neopixel stick (strip_a) lights up after the PIR sensors detects motion and goes off after 2 seconds. Then strip_b lights up but, never goes off again. I created a colorWipe for each strip too.
What am I missing?
Thanks for the help. Bob

Code: Select all

/* PIR sensor that turns on a Strip of LED neo pixles
 
 */

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(8, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(8, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_c = Adafruit_NeoPixel(8, 5, NEO_GRB + NEO_KHZ800);

int pirPin = 2;


void setup() {

  pinMode(pirPin, INPUT);
  
  Serial.begin(9600);

  strip_a.begin();
  strip_b.begin();
  strip_c.begin();

  strip_a.show(); // Initialize all pixels to 'off'
  strip_b.show();
  strip_c.show(); 
}

void loop() {

  if (digitalRead(pirPin) == HIGH)
  {
    Serial.println("MOVEMENT");
    strip_a.setBrightness(64);
    colorWipe(strip_a.Color(127, 127, 127), 50);
    delay(2000);
    colorWipe(strip_a.Color(0, 0, 0), 50);
    strip_a.show();

    delay(2000);
    
    strip_b.setBrightness(64);
    colorWipe2(strip_b.Color(127,127,127), 50);
    strip_b.show();
    delay(2000);
    colorWipe(strip_b.Color(0, 0, 0), 50); 
    strip_b.show();
    
    delay(2000);
  
    strip_c.setBrightness(64);
    colorWipe3(strip_c.Color(127,127,127), 50);
    strip_c.show();
    delay(2000);
    colorWipe(strip_c.Color(0, 0, 0), 50);   
    strip_c.show();  
     
  }
}
 
 //colorWipe for strip_a 
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_a.numPixels(); i++) {
      strip_a.setPixelColor(i, c);
      strip_a.show();
      delay(wait);
    }
}

 //colorWipe for strip_b 
void colorWipe2(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_b.numPixels(); i++) {
      strip_b.setPixelColor(i, c);
      strip_b.show();
      delay(wait);
    }
}

 //colorWipe for strip_c 
void colorWipe3(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_c.numPixels(); i++) {
      strip_c.setPixelColor(i, c);
      strip_c.show();
      delay(wait);
    }
}

User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Re: Neopixel strip on and off

Post by robertd5 »

Hold the presses
I just figured it out

In the code when I was trying to turn off strip_b, I typed
colorWipe(strip_b.Color(0, 0, 0), 50);

It needs to be
colorWipe2(strip_b.Color(0, 0, 0), 50);

I missed adding the 2

Despite looking at it the last 2 hours

I will try to follow up this post with some pictures of the final project

Thanks Bob
Bob

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel strip on and off

Post by adafruit_support_bill »

Hold the presses
I just figured it out
Congratulations! Code may may look like gibberish when you are first introduced to it. But once you get in there and start making changes, you start to get a feel for how it all fits together. Happy hacking!

User avatar
robertd5
 
Posts: 8
Joined: Tue May 14, 2013 8:01 pm

Re: Neopixel strip on and off

Post by robertd5 »

Hello
Just a follow up to this project.

Heres is link to a quick video of the light animation we created using the ProTrinket and the 8 LED strips.

https://youtu.be/Rw4k-fHZhbk

The LEDs are mounted in 3D printed enclosures.

The display highlights products that require corn. I helped some FFA students at our high school where I am a Technology Education Teacher. The display placed 7th in the field of 30+.

Here is the final code.

Code: Select all

/* PIR sensor that turns on a Strip of LED neo pixles
 
 */

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(8, 9, NEO_GRB + NEO_KHZ800); //back left
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(8, 10, NEO_GRB + NEO_KHZ800); //front left
Adafruit_NeoPixel strip_c = Adafruit_NeoPixel(8, 11, NEO_GRB + NEO_KHZ800); //front right
Adafruit_NeoPixel strip_d = Adafruit_NeoPixel(8, 12, NEO_GRB + NEO_KHZ800); //back right

int pirPin = 3;


void setup() {

  pinMode(pirPin, INPUT);
  

  strip_a.begin();
  strip_b.begin();
  strip_c.begin();
  strip_d.begin();

  strip_a.show(); // Initialize all pixels to 'off'
  strip_b.show();
  strip_c.show(); 
  strip_d.show();
}

void loop() {

  if (digitalRead(pirPin) == HIGH)
  {
    strip_a.setBrightness(255);
    colorWipe(strip_a.Color(255, 255, 102), 25);
    delay(5000);
    colorWipe(strip_a.Color(0, 0, 0), 50);
    strip_a.show();

    delay(20);
    
    strip_b.setBrightness(255);
    colorWipe2(strip_b.Color(255, 255, 102), 50);
    strip_b.show();
    delay(5000);
    colorWipe2(strip_b.Color(0, 0, 0), 50); 
    strip_b.show();
    
    delay(20);
  
    strip_c.setBrightness(255);
    colorWipe3(strip_c.Color(255, 255, 102), 50);
    strip_c.show();
    delay(5000);
    colorWipe3(strip_c.Color(0, 0, 0), 50);   
    strip_c.show();  
    
    delay(20);
    
    strip_d.setBrightness(255);
    colorWipe4(strip_d.Color(255, 255, 102), 50);
    strip_d.show();
    delay(5000);
    colorWipe4(strip_d.Color(0, 0, 0), 50); 
    strip_d.show();
    
    delay(20);
     
  }
}
 
 //colorWipe for strip_a 
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_a.numPixels(); i++) {
      strip_a.setPixelColor(i, c);
      strip_a.show();
      delay(wait);
    }
}

 //colorWipe for strip_b 
void colorWipe2(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_b.numPixels(); i++) {
      strip_b.setPixelColor(i, c);
      strip_b.show();
      delay(wait);
    }
}

 //colorWipe for strip_c 
void colorWipe3(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_c.numPixels(); i++) {
      strip_c.setPixelColor(i, c);
      strip_c.show();
      delay(wait);
    }
}

 //colorWipe for strip_d 
void colorWipe4(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_d.numPixels(); i++) {
      strip_d.setPixelColor(i, c);
      strip_d.show();
      delay(wait);
    }
}
Thanks for the Support.

Bob

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Neopixel strip on and off

Post by adafruit_support_bill »

Congratulations! And thanks for the follow-up post.

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

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”