Motion Sensor LED Strip with Reset Button

Hello, I have made a program and setup that has a motion sensor and a LED light strip. When the motion sensor is triggered it turns on the LED strip to whatever Animation i set it to. I am trying to implement a button that you can press that turns off the animation and resets everything so i can trip the motion sensor again. The Program is attached i will also put the segment that controls the motion sensor below.

void loop() {



 senseMotion = digitalRead(PIR);

 if (senseMotion == HIGH) {    // Tells lights to turn on
   scanner(127,0,127, 15); //Tells what animation for the lights to play
   strip.show(); // Initialize all pixels to 'off'
   delay(100);

 } else {
       val = digitalRead(ButtonPIN);
       if (val == HIGH) {
         strip.Color(0,0,0);
         strip.show();
        
       }


 }
}

LEDMOTION.ino (4.41 KB)

Is that all the code?
Please post it all.

Here is all the code.

#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, 6, NEO_GRB + NEO_KHZ800);

const byte PIR = 2;   // motion detector input pin
byte senseMotion = 0; // variable to hold current state of motion detector
int buttonPIN = 4;
int val = 0;

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(PIR, INPUT);
  pinMode(buttonPIN, INPUT);


}


// 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 myCrap(uint32_t c, uint8_t wait) {
  for (uint16_t k = 0; k < strip.numPixels(); k++) {

    strip.setPixelColor(2 * k, c);
    strip.show();
    delay(wait);

  }


}



void myCrap2(uint32_t c, uint8_t wait) {
  for (uint16_t k = 0; k < strip.numPixels(); k++) {

    strip.setPixelColor((2 * k + 1), 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);
  }
}


// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait) {
  int i;

  for (i = 0; i < strip.numPixels(); i++) strip.setPixelColor(i, 0);

  for (i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    strip.setPixelColor(i, 0);
    delay(wait);
  }

  strip.show();
}


// Input a value 0 to 255 to get a color value.
// The colors 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);
  }
}


// KITT Effect
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
  int i, j, pos, dir;

  pos = 0;
  dir = 1;

  for (i = 0; i < ((strip.numPixels() - 1) * 8); i++) {
    // Draw 5 pixels centered on pos.  setPixelColor() will clip
    strip.setPixelColor(pos - 2, strip.Color(r / 4, g / 4, b / 4));
    strip.setPixelColor(pos - 1, strip.Color(r / 2, g / 2, b / 2));
    strip.setPixelColor(pos, strip.Color(r, g, b));
    strip.setPixelColor(pos + 1, strip.Color(r / 2, g / 2, b / 2));
    strip.setPixelColor(pos + 2, strip.Color(r / 4, g / 4, b / 4));

    strip.show();
    delay(wait);
    for (j = -2; j <= 2; j++)
      strip.setPixelColor(pos + j, strip.Color(0, 0, 0));
    pos += dir;
    if (pos < 0) {
      pos = 1;
      dir = -dir;
    } else if (pos >= strip.numPixels()) {
      pos = strip.numPixels() - 2;
      dir = -dir;
    }
  }
}




void loop() {



 senseMotion = digitalRead(PIR);

 if (senseMotion == HIGH) {    // Tells lights to turn on
   scanner(127,0,127, 15); //Tells what animation for the lights to play
   strip.show(); // Initialize all pixels to 'off'
   delay(100);

 } else {
       val = digitalRead(buttonPIN);
       if (val == HIGH) {
         strip.Color(0,0,0);
         strip.show();
        
       }


 }
}



//Monocramatic Effect Sequence
//colorChase(strip.Color(127,   0, 127), 10); // Violet
//colorWipe(strip.Color(127, 0, 127), 10); // Violet
//myCrap(strip.Color(127,0,127),10); //Violet
//scanner(127,0,127, 15); // Violet

//myCrap2(strip.Color(0,0,0),10); // Off
//wave(strip.Color(127,0,127), 2, 40); // Violet
//rainbow(20);
//rainbowCycle(20);

@Beamer25, do not cross-post. Other thread removed.

You need to implement the anamation was a state machine.
That means moving all the delays and replacing the for loop with a one shot code. That is code that does one iteration and then returns. I have posted my example of this dozens of times lately.

Do not cross post. I have reported your other post, it will probably be deleted.
Do read the how to use this forum sticky post for the rules here.
Cross posting make people cross.

Thank you I will try that and very sorry, new to the forms.

Thanks,
Colton

I put the code I had in the loop into a void setup and i tried to compile it and it gave me

C:\Users\COLTON~1\AppData\Local\Temp\ccgtTII3.ltrans0.ltrans.o: In function `main':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

collect2.exe: error: ld returned 1 exit status

Using library Adafruit_NeoPixel at version 1.1.7 in folder: C:\Users\Colton Beam\Documents\Arduino\libraries\Adafruit_NeoPixel 

exit status 1
Error compiling for board Arduino/Genuino Uno.[code]

I know there must be something wrong with the code, here’s what i have.

#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(61, 6, NEO_GRB + NEO_KHZ800);

const byte PIR = 2;   // motion detector input pin
byte senseMotion = 0; // variable to hold current state of motion detector
int buttonPIN = 4;
int val = 0;

void setup () {
  pinMode(PIR, INPUT);
  pinMode(buttonPIN, INPUT);

  senseMotion = digitalRead(PIR);
  if (senseMotion == HIGH) {
    rainbow(20);
    strip.show();

  } else {
    val = digitalRead(buttonPIN);
    if (val == HIGH) {
      strip.Color(0, 0, 0);
      strip.show();
    }
  }
}



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


void myCrap(uint32_t c, uint8_t wait) {
  for (uint16_t k = 0; k < strip.numPixels(); k++) {

    strip.setPixelColor(2 * k, c);
    strip.show();


  }


}



void myCrap2(uint32_t c, uint8_t wait) {
  for (uint16_t k = 0; k < strip.numPixels(); k++) {

    strip.setPixelColor((2 * k + 1), c);
    strip.show();


  }


}



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();

  }
}

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

  }
}


// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait) {
  int i;

  for (i = 0; i < strip.numPixels(); i++) strip.setPixelColor(i, 0);

  for (i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    strip.setPixelColor(i, 0);
  }

  strip.show();
}


// Input a value 0 to 255 to get a color value.
// The colors 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);
  }
}


// KITT Effect
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
  int i, j, pos, dir;

  pos = 0;
  dir = 1;

  for (i = 0; i < ((strip.numPixels() - 1) * 8); i++) {
    // Draw 5 pixels centered on pos.  setPixelColor() will clip
    strip.setPixelColor(pos - 2, strip.Color(r / 4, g / 4, b / 4));
    strip.setPixelColor(pos - 1, strip.Color(r / 2, g / 2, b / 2));
    strip.setPixelColor(pos, strip.Color(r, g, b));
    strip.setPixelColor(pos + 1, strip.Color(r / 2, g / 2, b / 2));
    strip.setPixelColor(pos + 2, strip.Color(r / 4, g / 4, b / 4));

    strip.show();
    for (j = -2; j <= 2; j++)
      strip.setPixelColor(pos + j, strip.Color(0, 0, 0));
    pos += dir;
    if (pos < 0) {
      pos = 1;
      dir = -dir;
    } else if (pos >= strip.numPixels()) {
      pos = strip.numPixels() - 2;
      dir = -dir;
    }
  }
}

You have not got a loop function defined. You need to have a loop function when programming on the Arduino.

You had one before why have you removed it?