質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Q&A

解決済

1回答

2193閲覧

RFIDで2枚のカードにオンとオフの機能を持たせたい

fullaction

総合スコア9

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

0グッド

0クリップ

投稿2017/07/10 10:42

###前提・実現したいこと
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は手元にあるものに変えてテストはしてみました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

まずは”1つ”の”RFID”での動作を確立して、続いて2台の動作を確立するのがセオリー。
いきなり自分の思う通りに動く確率は低いです。

なので”なぜ?”を一つずつ潰す手法が一番近道ですが。

投稿2017/07/12 11:15

MasahikoHirata

総合スコア3747

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fullaction

2017/07/15 10:39

回答ありがとうございます。 返信が遅くなり申し訳ございません。 確かに1つずつ行う方が確実ですね。 もう少し自分で勉強してきます。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問