Go Down

Topic: Unable to compile (Read 383 times) previous topic - next topic

smallpoul

Maybe a stupid error but i'm not able to compile this code, it always tell me that the KeyCode was not declare in the scope.
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];
String keyCode;

String  master = "4B00108513470F";

// 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() {
 
  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
        keyCode = code;
        keyCode = keyCode.substring(0,14);
        if (KeyCode == master)
          Serial.println("Master key passed");
           
      }
      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
    }
  }
 
  }


I declare the KeyCode at the statup so why this error
Thanks

Grumpy_Mike

Code: [Select]
keyCode = code;
        keyCode = keyCode.substring(0,14);
        if (KeyCode == master)

keyCode is not the same as KeyCode
Case matters.

smallpoul

I'm probably slow today, sorry, i don't understand what you means?

HazardsMind

KeyCode  and keyCode they are NOT the same. This type of programing is case sensitive.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Grumpy_Mike

In this line:-
Code: [Select]
if (KeyCode == master)
it is the first time the compiler has seen the variable KeyCode.
Previously it has only been told about the variable keyCode  which is a different variable.
The first starts with a capital letter and the second a lower case letter. This means they are different variables.

smallpoul

Sorry for the stupid error thanks very much. For sure now it work

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy