Go Down

Topic: compare char to char (Read 694 times) previous topic - next topic

smallpoul

It seems to work now but could you tell me how can i flush the array after print have been done cause now it always print after the good card have been pass.
thanks

AWOL

Can't you just set the index, and write a zero into the first location in the array?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
Can't you just set the index, and write a zero into the first location in the array?

Even better would be to make the arrays one element larger and keep them NULL terminated as data is added. That way you can safely use them as strings (including using the more intuitive strcmp()).

smallpoul

Got it work now, just one last thing, here the code:

Code: [Select]
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Re-Modified for Arduino and 125Khz JsxzLz RFID Kit from Ebay by Biohazard

// RFID reader comes with 11 pins: D3 D2 D1 Rest Mcst Gnd L1 L2 PC TX VCC
// We need these to be connected:
// Rest to Arduino pin 2
// Gnd to Arduino GND
// L1 and L2 to the antenna
// TX to Arduino RX0
// VCC To Arduino 5V


int  val = 0;
char code[14];
char michael[14] = {'4', 'B', '0', '0', '1', '0', '8', '5', '1', '3', '4', '7', '0', 'F'};
char emilie[14] =  {'0', '5', '0', '0', '1', '5', '1', '5', '6', '7', '3', '9', '0', 'D'};;


// 10 digits card code
// 2 digits parity bits

int bytesread = 0;

void setup() {

  Serial.begin(9600);     // RFID reader TX pin, Baud rate: 9600, Data bits: 8, stop bit: 1.
  pinMode(2,OUTPUT);      // Set digital pin 2 as OUTPUT to connect it to the RFID RESET pin
  digitalWrite(2, HIGH);  // Activate the RFID reader
  Serial.println("rfid ready to read");
 



void loop() {
 
   boolean e_card = true;
   boolean m_card = true;
  if(Serial.available() > 0) {            // if data available from reader
    if((val = Serial.read()) == 10) {     // check for header
      bytesread = 0;
      while(bytesread < 14) {             // read 14 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) {  // if header or stop bytes before the 10 digit reading
            break;                        // stop reading
          }
          code[bytesread] = val;          // add the digit           
          bytesread++;                    // ready to read next digit 
        }
      }
      if(bytesread == 14) {         // if 14 digit read is complete
        if( memcmp(code, michael,14) != 0) m_card = false;
        if( memcmp(code, emilie,14) != 0) e_card = false;
       
        if (m_card)   
          {
            Serial.println("welcome Michael");
          }
         else if (e_card)
            {
            Serial.println("welcome Emilie");
            }
         else;
            {
            Serial.println("Unknow tag"); 
            }
           
      }
      bytesread = 0;
      digitalWrite(2, LOW);               // deactivate the RFID reader for a moment so it will not flood
      delay(1500);                        // wait for a bit
      digitalWrite(2, HIGH);              // Activate the RFID reader
    }
  }
 
  }
 



Why i always getting unknow tag event if it a valide one.

If i pass a good one it also print in unknow tag
rfid ready to read
welcome Emilie
Unknow tag

Thanks

PaulS

Code: [Select]
         else;
            {
            Serial.println("Unknow tag"); 
            }

What's that semicolon doing after the else statement?

Go Up