本帖最後由 curitis 於 2010-4-4 03:52 編輯
最近 因為需要使用RFID做出類似介面的裝置
而我現在想要在一個arduino上
裝入3個RFID read用來偵測個別的RFID tag訊號
而在最後同時顯示出3各別的訊號
像是: 0415ADAB82、0415AF5A82、0415AF0D27
而若之中有一組沒有的話則顯示空白
我在google上有找到相關資料
不過只能顯示出一組
程式碼如下
因為我是新手對程式也沒有概念
請各位可以給我指導嗎?
還有可以推薦我要撰寫Arduino這類的程式
從什麼地方下手或看什麼之類的書會比較有效率
謝謝
- #include <SoftwareSerial.h>
- #define rxPin 2
- #define txPin 3
- #define ledPin 13
- // set up a soft serial port
- SoftwareSerial mySerial(rxPin, txPin);
- int val = 0;
- char code[10];
- int bytesread = 0;
- void setup() {
- // define pin modes for tx, rx, led pins:
- pinMode(rxPin, INPUT); // Set rxPin as INPUT to accept SOUT from RFID pin
- pinMode(txPin, OUTPUT); // Set txPin as OUTPUT to connect it to the RFID /ENABLE pin
- pinMode(ledPin, OUTPUT); // Let the user know whats up
- // set the data rate for the serial ports
- mySerial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
- Serial.begin(9600); // Serial feedback for debugging in Wiring
- // say something
- Serial.println("Hello World!");
- }
- void loop() {
- digitalWrite(txPin, LOW); // Activate the RFID reader
- digitalWrite(ledPin, LOW); // Turn off debug LED
-
- if((val = mySerial.read()) == 10) { // check for header
- bytesread = 0;
-
- while(bytesread<10) { // read 10 digit code
- val = mySerial.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 == 10) { // If 10 digit read is complete
- digitalWrite(txPin, HIGH); // deactivate RFID reader
- digitalWrite(ledPin, HIGH); // activate LED to show an RFID card was read
- // Serial.print("TAG code is: "); // possibly a good TAG
- Serial.println(code); // print the TAG code
- }
-
- bytesread = 0;
- delay(2000); // wait for a second to read next tag
- }
- }
複製代碼
|