Code for RFID Robot
Dependencies: DebounceIn HTTPClient ID12RFID SDFileSystem TextLCD WiflyInterface iniparser mbed
RFID.cpp@0:9fd64882c5aa, 2013-12-10 (annotated)
- Committer:
- 4180skrw
- Date:
- Tue Dec 10 02:17:48 2013 +0000
- Revision:
- 0:9fd64882c5aa
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180skrw | 0:9fd64882c5aa | 1 | #include "RFID.h" |
4180skrw | 0:9fd64882c5aa | 2 | |
4180skrw | 0:9fd64882c5aa | 3 | //Takes in vector by reference and populates it with unique RFID values |
4180skrw | 0:9fd64882c5aa | 4 | //until pb21 is pressed. |
4180skrw | 0:9fd64882c5aa | 5 | int readTagSequence(std::vector<int>& v) |
4180skrw | 0:9fd64882c5aa | 6 | { |
4180skrw | 0:9fd64882c5aa | 7 | int currTag; |
4180skrw | 0:9fd64882c5aa | 8 | int size = 0; |
4180skrw | 0:9fd64882c5aa | 9 | printLCD("Scan tag", NULL); |
4180skrw | 0:9fd64882c5aa | 10 | while (select) { |
4180skrw | 0:9fd64882c5aa | 11 | if(rfid.readable()) { |
4180skrw | 0:9fd64882c5aa | 12 | currTag = rfid.read(); |
4180skrw | 0:9fd64882c5aa | 13 | size++; |
4180skrw | 0:9fd64882c5aa | 14 | v.resize(size); |
4180skrw | 0:9fd64882c5aa | 15 | v[size-1] = currTag; |
4180skrw | 0:9fd64882c5aa | 16 | char line1[16]; |
4180skrw | 0:9fd64882c5aa | 17 | sprintf(line1, "%d", v[size-1]); |
4180skrw | 0:9fd64882c5aa | 18 | printLCD(line1, "added to list"); |
4180skrw | 0:9fd64882c5aa | 19 | wait(1.5); |
4180skrw | 0:9fd64882c5aa | 20 | printLCD("Scan tag", NULL); |
4180skrw | 0:9fd64882c5aa | 21 | } |
4180skrw | 0:9fd64882c5aa | 22 | else if(!back) return 0; |
4180skrw | 0:9fd64882c5aa | 23 | } |
4180skrw | 0:9fd64882c5aa | 24 | return 1; |
4180skrw | 0:9fd64882c5aa | 25 | } |
4180skrw | 0:9fd64882c5aa | 26 | |
4180skrw | 0:9fd64882c5aa | 27 | //Reads a single RFID tag, and returns value |
4180skrw | 0:9fd64882c5aa | 28 | int readTag() |
4180skrw | 0:9fd64882c5aa | 29 | { |
4180skrw | 0:9fd64882c5aa | 30 | printLCD("Scan tag", NULL); |
4180skrw | 0:9fd64882c5aa | 31 | int currTag = 0; |
4180skrw | 0:9fd64882c5aa | 32 | while (!currTag) { |
4180skrw | 0:9fd64882c5aa | 33 | if (rfid.readable()) { |
4180skrw | 0:9fd64882c5aa | 34 | currTag = rfid.read(); |
4180skrw | 0:9fd64882c5aa | 35 | char line1[16]; |
4180skrw | 0:9fd64882c5aa | 36 | sprintf(line1, "%d", currTag); |
4180skrw | 0:9fd64882c5aa | 37 | printLCD(line1, "read"); |
4180skrw | 0:9fd64882c5aa | 38 | wait(1.5); |
4180skrw | 0:9fd64882c5aa | 39 | return currTag; |
4180skrw | 0:9fd64882c5aa | 40 | } |
4180skrw | 0:9fd64882c5aa | 41 | else if (!back) { |
4180skrw | 0:9fd64882c5aa | 42 | return 0; |
4180skrw | 0:9fd64882c5aa | 43 | } |
4180skrw | 0:9fd64882c5aa | 44 | } |
4180skrw | 0:9fd64882c5aa | 45 | return currTag; |
4180skrw | 0:9fd64882c5aa | 46 | } |