###前提・実現したいこと
RC522を使用しオン・オフをそれぞれ別々のカードにしたいのですが、さっぱり方法がわかりません。
とあるサイトでスケッチをDLして試してみたのですが、エラーが出て手詰まりです。
何がダメだと言われているのでしょうか。
たぶん基本的なことなのでしょうが…。
###発生している問題・エラーメッセージ
エラーメッセージ FID_TwoCards_Switch:25: error: expected unqualified-id before '.' token MFRC522.init(); ^ RFID_TwoCards_Switch:34: error: expected primary-expression before '.' token if (MFRC522.isCard()) ^ RFID_TwoCards_Switch:36: error: expected primary-expression before '.' token if (MFRC522.readCardSerial()) ^ RFID_TwoCards_Switch:43: error: expected primary-expression before '.' token if (MFRC522.serNum[i] != master[i]) /// comparing arrray elements from MFRC522 card and defined cards (!= means "not equal"); ^ RFID_TwoCards_Switch:51: error: expected primary-expression before '.' token if (MFRC522.serNum[j] != secondary[j]) ^ RFID_TwoCards_Switch:66: error: expected unqualified-id before '.' token MFRC522.Halt(); ^ exit status 1 expected unqualified-id before '.' token ###該当のソースコード include <Wire.h> include <SPI.h> include <MFRC522.h> define SS_PIN 10 define RST_PIN 9 define logicSwitch 6 //define switching pin MFRC522 rfid(SS_PIN, RST_PIN); int master[] = {147, 17, 57, 69}; // master[x] where x is number of card uid segments. And the brackets: {card uid in dec}. This is where you define your unique card id. int secondary[] = {242, 209, 57, 213}; //example of second MFRC522 card int i,j; void allowed(); void denied(); boolean pinState; void setup() { Serial.begin(9600); SPI.begin(); MFRC522.init(); pinMode(logicSwitch, OUTPUT); digitalWrite(logicSwitch, LOW); pinState = digitalRead(logicSwitch); } void loop() { if (MFRC522.isCard()) { if (MFRC522.readCardSerial()) { /* Reading card */ ///////////////////////////////////////////////////////////// //verification of a card. Checking if card presented matches with the card described above. for (i = 0; i < sizeof(master); i++) /// for loop to pass through all array elements { if (MFRC522.serNum[i] != master[i]) /// comparing arrray elements from MFRC522 card and defined cards (!= means "not equal"); { /// MFRC522.serNum[i] points to a library structure where the array is stored when the card is read break; /// if array elements mismaches - breaks the for loop resulting in lower variable "i" value } } ////////////////////////////////////////////////////////////////// for (j = 0; j < sizeof(secondary); j++) /// checking another card { if (MFRC522.serNum[j] != secondary[j]) { break; } } /////////////////////////////////////////////////////////////////// if (i == 4 || j == 4) { /// change the numbers with the number of your uid segments (|| means "or" operation). i must be equal to number of "master" number of elements and j must be equal to "secondary" number of elements allowed(); } else{ /// if none of numers matches - calls for "denied" function. denied(); } ///////////////////////////////////////////////////////////////////////// } } MFRC522.Halt(); } void allowed() //// do something in this loop that you want to do if allowed. In my case - I switch things. { Serial.println("Allowed"); digitalWrite(logicSwitch, !digitalRead(logicSwitch)); // invert the pin status from previous pin status pinState = digitalRead(logicSwitch); // read pin status delay(1000); // always a good idea to make a delay } void denied() //// do something in this loop that you want to do if denied { Serial.println("Denied"); delay(1000); } ###試したこと UIDは手元にあるものに変えてテストはしてみました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/15 10:39