RFIDtest.ino-69f28696/RFIDtest.ino
2017-05-31 19:48:42 +02:00

101 lines
2.2 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//Based on example code from SEEED studio wiki
//for 125kHz GROVE RFID reader
//GPL V3
/*
link between the computer and the SoftSerial Shield
at 9600 bps 8-N-1
Computer is connected to Hardware UART
SoftSerial Shield is connected to the Software UART:D2&D3
*/
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
String intest=""; //input string
char buffchar;
int count = 0; // counter for buffer array
int led = 13;
void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop()
{
// if date is coming from software serial port ==> data is coming from SoftSerial shield
RFIDread();
if (intest.equals("5300C59F363F"))
{
Serial.println(" match "); // if no data transmission ends, write buffer to hardware serial port
Serial.println(intest);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
intest = "";
}
else if (intest.endsWith(""))
{
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
Serial.println(intest);
intest="";
}
}
void RFIDread()
{
if (SoftSerial.available())
{
while(SoftSerial.available()) // reading data into char array
{
buffchar = SoftSerial.read(); // writing data into array
//Serial.println(int(buffchar));
intest += buffchar;
if (int(buffchar)= 3)break;
//count++;
// if(buffchar=' ')break;
}
}
}
void clearBufferArray() // function to clear buffer array
{
// clear all index of array with command NULL
for (int i=0; i<count; i++)
{
buffer[i]=NULL;
}
intest = "";
}