Hi,
I am trying to have a variable with two possibility , I try this but did not work
int code[] = {191,188,191,73 || 218,74,169,137} ;
what is the right syntax please?
Thx
david
Hi,
I am trying to have a variable with two possibility , I try this but did not work
int code[] = {191,188,191,73 || 218,74,169,137} ;
what is the right syntax please?
Thx
david
There isn't any correct syntax for that. You have to explain what you want to do with code[].
|| is logical OR and will give the value 1 or true
did you intend to use bitwise OR |
int code[] = {191,188,191,73 | 218,74,169,137};
which gives the value 219 to array element code[3]
it is more usual to use bitwise operators with hexadecimal values
This variable is a RFID card code (like a ip address), I just want to have two cards that activate my relay
I tried bitwise OR | already not working
Here is how code [] is used:
int i = 0;
boolean match = true;
while(i<rfid.uid.size)
{
if(!(rfid.uid.uidByte == code*))*
* {*
* match = false;*
* }*
* i++;*
* }*
* if(match)*
* {*
Hope it's more clear
Thx Delta_G I was looking in that direction, but I did not write in Itallics, I just done a copy paste, and nothing was in Itallics, anyway thanks a lot
Well not a good day for me, not my first time but totaly forgot the Tags
I found the solution, if that can help
int code1 = "191,188,191,73" ;
int code2 = "218,74,169,137" ;
...
...
int i = 0;
boolean match = true;
while(i<rfid.uid.size)
{
if(!(rfid.uid.uidByte[i] == code1) || code2))
{
match = false;
}
i++;
}
if(match)
{
No, that will not work.
You were right, String should have been used, my code worked fine with 25 different cards and I assumed that it was correct
And yes internet offer a ton of code, but not much real explaination. I just wanted to know where were my mistake, that is why forum are for, no?
Anyway you helped me a lot, so I will pass your grumpy mood.
Here is the correction
String code1 = "191,188,191,73" ;
String code2 = "218,74,169,137" ;
String uidString;
..
..
uidString = String(rfid.uid.uidByte[0])+","+String(rfid.uid.uidByte[1])+","+String(rfid.uid.uidByte[2])+ ","+String(rfid.uid.uidByte[3]);
..
..
int i = 0;
boolean match = true;
while(i<rfid.uid.size)
{
if(!(uidString == code1 || code2))
{
match = false;
}
i++;
}
if(match)
{
The String class is trouble. It has memory management issues that can cause mysterious crashes because of the small memory footprint on an AVR or similar processor.
Thx Aarg. I will keep that in mind and see another solution if I have trouble.