Loading...
Pages: [1]   Go Down
Author Topic: Unable to compile  (Read 126 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
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: 269
Posts: 25392
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: 50
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
Edison Member
*
Karma: 27
Posts: 1539
"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

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 269
Posts: 25392
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: 50
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
Print
 
Jump to: