Coding help requested

-3

Hey so i started trying to make a project with my arduino (i dont really know how to code) and i just keep getting errors with my code is someone able to help me? here is what i have

#include <SPI.h>
#include <MFRC522.h>
#include <IRLibAll.h>
#include <Servo.h>

#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 2 //buzzer pin
#define MY_PROTOCOL NEC

uint32_t Previous;//handles NEC repeat codes
IRdecode myDecoder;

/*Edit these settings*/
//Password and security
String pass = "1234"; //Password to unlock. be sure to edit the '5' inside '[]' to password length +1.
int chances = 3; //Chances before buzzer will start to buzz continuously.
bool afterChances = true; /*Is possible to enter password after
  running out of chances. true = yes. (not recommended to set
  false, Arduino must be restarted to enter password if set
  to false.).If set true, buzzer will stop when correct password is
  entered after running out of chances.*/


//Pins
int RECV_PIN = 11; //IR Reciever pin (PWM).
int greenLed = 7; //Green LED pin.
int redLed = 8; //Red Led pin.
int buzzer = 4; //Buzzer pin.

//remote buttons
#define one 0xc9767f76 //Your button 1 IR HEX code (in lower case). eg.: ff63ad
#define two  0xc8155ab1 //Your button 2 IR HEX code (in lower case).
#define three  0xb6996dae
#define four  0x969ae844
#define five  0x4aafac67
#define six  0x9c2a936c
#define seven  0x833ed333
#define eight  0x55f2b93
#define nine  0xde78b0d0
#define zero  0xf32f72d7
#define btnreset  0x3f23f43 //Your Reset button IR hex code.

//Misc
bool shouldBeep = true;
bool unlockSound = true;

/*Don't edit anything below this if you don't what you are doing.
   Somethimes, it can cause high load to your arduino.
*/
bool locked = true;
String cPass = "";
int chance = 0;
String cmp = "----Distro Studios-----\n";
IRrecv irrecv(RECV_PIN);
IRdecode results;
String str2 = "os-----\n";

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name

void setup() 
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(3); //servo pin
  myServo.write(0); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  //noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();
  irrecv.enableIRIn();
  Serial.begin(9600);
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  Serial.print(cmp);
 }
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "99 E0 A3 99") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    //tone(BUZZER, 500);
    delay(300);
    //noTone(BUZZER);
    myServo.write(180);
    delay(5000);
    myServo.write(0); //change this to when it is locked
    digitalWrite(LED_G, LOW);
  }

 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    //tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    //noTone(BUZZER);
 }
}


void loop2() {

  if (cmp.endsWith(str2) == false)
    Serial.print("Error!");
  else {
    myDecoder.decode();
     if(myDecoder.protocolNum==MY_PROTOCOL) {
         if(myDecoder.value==0xFFFFFFFF)
           myDecoder.value=Previous;
     switch(myDecoder.value)
    {
      case one:
        Serial.print("1");
        updatePass("1");
        break;
      case two:
        Serial.print("2");
        updatePass("2");
        break;
      case three:
        Serial.print("3");
        updatePass("3");
        break;
      case four:
        Serial.print("4");
        updatePass("4");
      break;
      case five:
        Serial.print("5");
        updatePass("5");
        break;
      case six:
        Serial.print("6");
        updatePass("6");
        break;
      case seven:
        Serial.print("7");
        updatePass("7");
        break;
      case eight:
        Serial.print("8");
        updatePass("8");
        break;
      case nine:
        Serial.print("9");
        updatePass("9");
        break;
      case zero:
        Serial.print("0");
        updatePass("0");
        break;
      case btnreset:
        resetPass();
        Serial.println("\nRESET");
        break;
      }
      irrecv.resume(); // Receive the next value
    }
    if (chance = chances)
      digitalWrite(buzzer, HIGH);//buzzer

    if (locked == true) {
      digitalWrite(redLed, HIGH);
      digitalWrite(greenLed, LOW);
    }
    else {
      digitalWrite(redLed, LOW);
      digitalWrite(greenLed, HIGH);
    }
  }
 }
}

bool updatePass(String ch) {
  if (locked == false)
    return false;
  beep();
  if (updatable() == true) {
    cPass += ch;
    if (cPass.length() < pass.length()) {

    }
    else {
      if (pass == cPass) {
        locked = false;
        digitalWrite(greenLed, HIGH);
        digitalWrite(redLed, LOW);
        chance = 0;
        Serial.println("\nUNLOCKED");
        if (unlockSound == true) {
          delay(60);
          digitalWrite(buzzer, HIGH);
          delay(150);
          digitalWrite(buzzer, LOW);
          delay(100);
          digitalWrite(buzzer, HIGH);
          delay(200);
          digitalWrite(buzzer, LOW);
        }
      }
      else {
        cPass = "";
        chance += 1;
        digitalWrite(buzzer, HIGH);
        delay(1000);
        digitalWrite(buzzer, LOW);
        Serial.println("\nWRONG PASSWORD!");
      }
    }
  }
}

bool updatable() {
  if (chance <= chances)
    return true;
  return afterChances;
}

void resetPass() {
  cPass = "";
  locked = true;
}

void beep() {
  if (shouldBeep == true) {
    digitalWrite(buzzer, HIGH);
    delay(60);
    digitalWrite(buzzer, LOW);
  }
}

can someone try to debug it for me? like i said i dont know how to code i just found this code somewhere and started editing it for what i want

arduino
asked on Stack Overflow May 17, 2020 by redbaron2k7

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0