Pages: [1]   Go Down
Author Topic: Unable to compile  (Read 278 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33292
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
keyCode = code;
        keyCode = keyCode.substring(0,14);
        if (KeyCode == master)
keyCode is not the same as KeyCode
Case matters.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Queens, New York
Offline Offline
Faraday Member
**
Karma: 83
Posts: 3393
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

KeyCode  and keyCode they are NOT the same. This type of programing is case sensitive.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33292
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In this line:-
Code:
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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: