So I am creating a password system using Neopixels and an IR remote. Lighting up each pixels once a button is pressed. I created 4 array variables with list of numbers inside to be used later. I also initialised z variable to be use later on the last part to check if the passwords are correct. Correct = all pixel blink green 3 times. Wrong all light up as red for 2 seconds. So my question is, for every if statements on the first part, do the digits actually get stores on the y[z] array? And, am I right to use if( z =8) to check if the number of digits inside y[z] is already 8 to start checking the password? Because, it does not seem to work, it does not enter in the if statements when checking if the password is correct or not. Also, the serial monitor is only showing 0s instead of the number of the button I am pressing :// is my application of array wrong? Thank you!
//INFRARED LIBRARY
#include <IRremote.h>
//ADAFRUIT PIXEL LIBRARY
#include <Adafruit_NeoPixel.h>
#define numpixels 8
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numpixels, 12);
const int receiver = 11;
int bryce[8] = {1,1,8,1,1,2,7,7,}; //passwords
int franchell[8] = {1,1,8,1,2,3,6,2};
int justyn[8] = {1,1,8,1,0,6,5,3};
int extra[8] = {1,1,9,8,7,6,5,4};
int x;
int y[8];//will be used to assign numbers
int z; //to activate correct or not
//receiver oject
IRrecv irrecv(receiver);
//decoder object
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();//receiving process
irrecv.blink13(true);
pixels.begin();
}
void loop()
{
if(irrecv.decode(&results)) //this checks to see if a code has been received
{
if(results.value == 0xFD30CF) //if the button press equals the hex value 0xC284
{
//maps 0 button
pixels.setPixelColor(x,pixels.Color(20,30,40));//GRAYISH black since black is not visible
pixels.show();
y[z]=0;
}
else if(results.value == 0xFD08F7) //if the button press equals the hex value 0xC284
{
//maps 1 button
pixels.setPixelColor(x,pixels.Color(0,0,255));//blue
pixels.show();
y[z]=1;
}
else if(results.value == 0xFD8877) //if the button press equals the hex value 0xC284
{
//maps 2 button
pixels.setPixelColor(x,pixels.Color(255,165,0));//orange
pixels.show();
y[z]=2;
}
else if(results.value == 0xFD48B7) //if the button press equals the hex value 0xC284
{
//maps 3 button
pixels.setPixelColor(x,pixels.Color(255,0,0));//red
pixels.show();
y[z]=3;
}
else if(results.value == 0xFD28D7) //if the button press equals the hex value 0xC284
{
//maps 4 button
pixels.setPixelColor(x,pixels.Color(0,255,0));//green
pixels.show();
y[z]=4;
}
else if(results.value == 0xFDA857) //if the button press equals the hex value 0xC284
{
//maps 5 button
pixels.setPixelColor(x,pixels.Color(0,255,255));//cyan
pixels.show();
y[z]=5;
}
else if(results.value == 0xFD6897) //if the button press equals the hex value 0xC284
{
//maps 6 button
pixels.setPixelColor(x,pixels.Color(128,0,128));//purple
pixels.show();
y[z]=6;
}
else if(results.value == 0xFD18E7) //if the button press equals the hex value 0xC284
{
//maps 7 button
pixels.setPixelColor(x,pixels.Color(255,255,0));//yellow
pixels.show();
y[z]=7;
}
else if(results.value == 0xFD9867) //if the button press equals the hex value 0xC284
{
//maps 8 button
pixels.setPixelColor(x,pixels.Color(255,0,255));//magenta
pixels.show();
y[z]=8;
}
else if(results.value == 0xFD58A7) //if the button press equals the hex value 0xC284
{
//maps 9 button
pixels.setPixelColor(x,pixels.Color(255,255,255));//white
pixels.show();
y[z]=9;
}
x++;
delay(1000);
irrecv.resume(); //receive the next value
Serial.print(y[8]);
}
if (z==8){
if((y[8]==bryce[8]) or (y[8]==franchell[8]) or (y[8]==justyn[8]) or (y[8]==extra[8]))
{
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,255,0));
pixels.show();
} delay(500); x=0;
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,0,0));
pixels.show();
}
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,255,0));
pixels.show();
} delay(500);
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,0,0));
pixels.show();
}
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,255,0));
pixels.show();
} delay(500);
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,0,0));
pixels.show();
}
}
else
{
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(255,0,0));
pixels.show();
} delay(2000); x=0;
for(int i =0; i<=8;i++)
{
pixels.setPixelColor(i,pixels.Color(0,0,0));
pixels.show();
}
}
}
}
//https://learn.sparkfun.com/tutorials/ir-communication/receiving-ir-example