Hello everyone. I have a problem with a project I'm working on. I'm building an access control system for multiple users. They all have unique passwords. What I'm trying to do is write an If statement that compares the users password to a string of passwords and if it matches access is allowed. As much as I research I don't know how to compare a single INT with a string or array of INT's This is what I have so far but obviously doesn't work. How can I compare a single INT with a pool of INT's. I just have it turning on the built in LED in this example just for testing purposes.
#include <RCSwitch.h>
int Pause = 2000;
int FrontDTPool[2] = { 12134312, 12134308 };
int RearDTPool[2] = { 12134308, 12134312 };
int FrontWBPool[2] = { 12134306, 12134312 };
int RearWBPool[2] = { 12134305, 12134312 };
unsigned long FrontDTMillis;
unsigned long RearDTMillis;
unsigned long FrontWBMillis;
unsigned long RearWBMillis;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(D2); // Receiver on interrupt 0 => that is pin #2
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
if (mySwitch.available()) {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
if ((mySwitch.getReceivedValue() == FrontDTPool[2]) && ((millis() - FrontDTMillis) >= Pause)) {
FrontDTMillis = millis();
digitalWrite(LED_BUILTIN, LOW);
}
if ((mySwitch.getReceivedValue() == RearDTPool[2]) && ((millis() - RearDTMillis) >= Pause)) {
RearDTMillis = millis();
digitalWrite(LED_BUILTIN, LOW);
}
if ((mySwitch.getReceivedValue() == FrontWBPool[2]) && ((millis() - FrontWBMillis) >= Pause)) {
FrontWBMillis = millis();
digitalWrite(LED_BUILTIN, LOW);
}
if ((mySwitch.getReceivedValue() == RearWBPool[2]) && ((millis() - RearWBMillis) >= Pause)) {
RearWBMillis = millis();
digitalWrite(LED_BUILTIN, LOW);
}
mySwitch.resetAvailable();
}
}
compare each array element one at a time and set a flag if any are unequal. It's easy but it takes a few lines of code. I hope you know already that you can index an array like RearDTPool[i]...
You define an array with 2 elements below (index 0, index 1)
You try to access index 2 (array element 3) below... this is beyond the bounds of the array.
If you have them turned on you will be getting compiler warnings about this.
EDIT: If you are trying to compare to EACH element [ ] of the array then you have to loop through each element... you can't compare the whole array in one go.