Good day all,
First off I am a beginner so apologies in advance if my questions are new-be ones. However I love this stuff so teach me what I am doing wrong.
I have a very basic project I am trying to have my NEOPixels Light up the front of a road case, and a second NEOPixels strip that light up the back of the case. Two PIR ( Motion Sensors) one for the front and one for the back. each PIR would control the strip assigned to it ( FRONT) & (BACK).
If no motion is detected the led's are at 30% brightness, if motion is detected that section got to 100%.
Override Switch to bypass the PIR Sensors. LED's stay at current intensity.
Lastly Priority override for all if an E-Stop is pressed the All lights go red.
None of it is working when I add it all together, it work if I have one component. What am I missing?
Curent code:
#include <Adafruit_NeoPixel.h>
int NeoLEDFront = 2; // the data pin for the NeoPixels Front
int NeoLEDRear = 5; // the data pin for the NeoPixels Rear
//int numPixels = 40; // How many NeoPixels we will be using
int FrontPixels = 20; // How Many NeoPixels Front
int RearPixels = 20; // How Many NeoPixels Rear
int ESTOP = 13;
int Override = 12;
int i = 0;
Adafruit_NeoPixel strip_Front = Adafruit_NeoPixel(FrontPixels, NeoLEDFront, NEO_GRB + NEO_KHZ800); // Instatiate the NeoPixel from the Library
Adafruit_NeoPixel strip_Rear = Adafruit_NeoPixel(RearPixels, NeoLEDRear, NEO_GRB + NEO_KHZ800); // Instatiate the NeoPixel from the Library
int r = 128; // Global RGB values, change to suit your needs
int g = 128;
int b = 128;
int MotionFront = 3; // Motion Sensor Input Side 1 Front
int MotionRear = 4; // Motion Sensor Input Side 1 Rear
void setup() {
pinMode(ESTOP, INPUT); //Estop input
pinMode(Override, INPUT); // Override Switch
pinMode(MotionFront, INPUT); // PRI Sensor Input
pinMode(MotionRear, INPUT); // PRI Sensor Input
pinMode(NeoLEDFront, OUTPUT); // NeoPixel Signal Output
pinMode(NeoLEDRear, OUTPUT); // NeoPixel Signal Output
strip_Front.begin(); // initialize the strip
strip_Rear.begin();
strip_Front.show(); // make sure it is visible
strip_Rear.show();
strip_Front.clear(); // Initialize all pixels to 'off'
strip_Rear.clear();
Serial.begin(9600);
}
void loop() {
if( digitalRead(ESTOP) == true ) {
Serial.println("E-STOP");
for( int i = 0; i < FrontPixels, RearPixels; i++ ) // if value is 0,0,0, then the pixel will be "off"
strip_Front.setPixelColor(i, 255, 0, 0 );
strip_Rear.setPixelColor(i, 255, 0, 0 );
}
if( digitalRead(Override) == true ) { // Check to see if the button is down
Serial.println("Override");
for( int i = 0; i < FrontPixels, RearPixels; i++ ) // if value is 0,0,0, then the pixel will be "off"
strip_Front.setPixelColor(i, 255, 255, 255 );
strip_Rear.setPixelColor(i, 255, 255, 255 );
}
if( digitalRead(MotionFront) == true ) { // Check to see if the button is down
Serial.println("Front Motion!");
for( int i = 0; i < FrontPixels; i++ ) // if value is 0,0,0, then the pixel will be "off"
strip_Front.setPixelColor(i, 255, 0, 0 );
}
if( digitalRead(MotionRear) == true ) { // Check to see if the button is down
Serial.println("Rear Motion!");
for( int i = 0; i < RearPixels; i++ ) // if value is 0,0,0, then the pixel will be "off"
strip_Rear.setPixelColor(i, 255, 255, 255 );
}
else {
Serial.println("Normal Operation");
for( int i = 0; i < FrontPixels, RearPixels; i++ )
strip_Front.setPixelColor(i, r, g, b);
strip_Rear.setPixelColor(i, r, g, b);
}
strip_Front.show();
strip_Rear.show();
// delay for the purposes of debouncing the switch
delay(10);
}