Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 3135|回復: 0
打印 上一主題 下一主題

RFID結合XBEE的程式碼

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-3-19 00:55:52 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 z159357z2000 於 2012-3-19 14:34 編輯

我正在做一個專題
是想要用RFID收到TAG的訊息用XBEE傳給出來
我是要把BUTTON變成RFID
請問程式是要怎麼合併了?

這是我的程式碼
XBEE:

const intbuttonPin = 12;
//
按鍵引腳數量

const int ledPin=
13;
// LED
引腳數量

// variableswill change:

int buttonState= 0;
//
變量讀取按鍵狀態

longpreviousMillis = 0;
//
將存儲LED被更新的最後一次

// the followvariables is a long because the time, measured in miliseconds,

// will quicklybecome a bigger number than can be stored in an int.

long interval =1000;
// interval at which toblink (milliseconds)

void setup() {


// initialize the LED pin as an output:


pinMode(ledPin, OUTPUT);


// initialize the pushbutton pin as an input:


pinMode(buttonPin, INPUT);


Serial.begin(9600);

}

void loop(){


// read the state of the pushbutton value:


buttonState = digitalRead(buttonPin);


// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:


if (buttonState == HIGH) {


// turn LED on:


digitalWrite(ledPin, HIGH);


Serial.println("apple");


delay(300);
// so won't send msg too many times


}


else {


// turn LED off:


digitalWrite(ledPin, LOW);


}


// Simply to keep xbee alive


unsigned long currentMillis = millis();


if(currentMillis - previousMillis >interval) {


// save the last time you blinked the LED


previousMillis = currentMillis;


Serial.println("sync");


}

}



RFID:

int val =0;

char code[10];

int bytesread =0;


void setup() {


Serial.begin(2400);// Serial RX pin(digital 0) 設為2400bps

pinMode(2,OUTPUT);// digital pin 2設為輸出,以便傳送訊號給RFID reader

}


voidloop() {

digitalWrite(0,LOW);                 //
啟動RFID reader

if(Serial.available()> 0) {          //
假如reader有資料讀入

   if((val = Serial.read()) == 10) {   //
檢查標頭是否為10

     bytesread = 0;

     while(bytesread<10){            

       if( Serial.available() > 0) {

         val = Serial.read();

         if((val == 10)||(val == 13)) { //假如讀到表示標頭的10或結束的13           

           break;                      //
停止讀取

         }

         code[bytesread] = val;         //紀錄讀入的值

         bytesread++;                  //準備讀取下一個位元

       }

     }

     if(bytesread == 10){             //
如果十個號碼皆讀取成功

       Serial.print("TAG code is: ");  

       Serial.println(code);           //
顯示TAG號碼

     }

     bytesread = 0;

     digitalWrite(0,HIGH);            //
關閉RFID reader

     delay(500);                     

   }

}

}

您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-6-17 07:29 , Processed in 0.186503 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表