为什么我的Arduino Uno无法运行我的门锁代码?

时间:2019-12-25 23:08:22

标签: arduino rfid arduino-ide

对不起,代码混乱,但是我想知道是否有人知道为什么不能在Arduino Uno上运行它?它用于分别由RFID和IR遥控器控制的上锁门,当我编辑void ir()部分的代码时,由于某种原因它停止工作。

我的代码:

#include <MFRC522.h>
#include "Stepper.h"
#include "IRremote.h"

#define SS_PIN 10
#define RST_PIN 9
#define ACCESS_DELAY 2000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN); 
#define STEPS  32   // Number of steps per revolution of Internal shaft
Stepper small_stepper(STEPS, 2, 4, 3, 5);
int  Steps2Take;  // 2048 = 1 Revolution
int receiver = 8; // Signal Pin of IR receiver to Arduino Digital Pin 6
IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'
bool locked = true;
int steps = 500;
// Create MFRC522 instance.
/*----- Variables, Pins -----*/



/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4



void setup() 
{
  irrecv.enableIRIn(); // Start the receiver
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();          // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Put your card to the reader...");
  Serial.println();

}


void rfid()
{
  // 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) == "B9 67 D6 6E") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    small_stepper.setSpeed(500); //Speed (Max 500)
    Steps2Take  =  steps;  // Rotate 500CW
    small_stepper.step(Steps2Take); //Do the steps
    delay(3000);
    Steps2Take  =  -steps;  // Rotate 500CW
    small_stepper.step(Steps2Take); //Do the steps  
  }

 else   {
    Serial.println(" Access denied");
    delay(3000);
  }
} 

void ir()
{   if (irrecv.decode(&results)) // have we received an IR signal?

  {
    switch(results.value)

    {

      case 0xFFA857: //VOL - pressed
                    if (locked == true){
                      small_stepper.setSpeed(500); //Speed (Max 500)
                      Steps2Take  =  steps;  // Rotate 500CW
                      small_stepper.step(Steps2Take); //Do the steps
                      locked = false;

                    }

      case 0xFF629D: //VOL + pressed              
                     if (locked == false){
                      small_stepper.setSpeed(500); //Speed (Max 500)
                      Steps2Take  =  -steps;  // Rotate 500 ACW
                      small_stepper.step(Steps2Take); //Do the steps
                      locked = true;

                    }
    }



  }
}


  }  



void loop()
{
  ir();
  rfid();

}


我的错误: /var/folders/5f/6gg5hb5174n1h9hmdy2pmn3w0000gp/T//ccQ6deD3.ltrans0.ltrans.o:在函数main': /private/var/folders/5f/6gg5hb5174n1h9hmdy2pmn3w0000gp/T/AppTranslocation/F6976C18-1AF6-4EB1-A8BD-1B9FBC53FC03/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to中循环 collect2:错误:ld返回1退出状态 找到多个库“ Stepper.h”  二手货:/ Users / Ulitimac / Documents / Arduino / libraries / Stepper  不使用:/private/var/folders/5f/6gg5hb5174n1h9hmdy2pmn3w0000gp/T/AppTranslocation/F6976C18-1AF6-4EB1-A8BD-1B9FBC53FC03/d/Arduino.app/Contents/Java/libraries/Stepper 退出状态1 为板Arduino / Genuino Uno编译时出错。

谢谢!

0 个答案:

没有答案