Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TSI mbed tsi_sensor
Fork of readMifare by
Diff: main.cpp
- Revision:
- 3:3c63af6987d3
- Parent:
- 2:96f420fa4a6e
--- a/main.cpp Mon Nov 03 05:48:29 2014 +0000
+++ b/main.cpp Mon Oct 26 10:06:28 2015 +0000
@@ -39,6 +39,9 @@
#include "mbed.h"
#include "Adafruit_PN532.h"
+#include "TSISensor.h"
+
+
#define SS PTD0
// PTD1 is also LED_BLUE, it will blink during SPI communication.
@@ -52,14 +55,25 @@
Serial pc(USBTX, USBRX);
Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
-
+float readVal = 0;
+float lastTouch = 0;
void loop(void);
+TSISensor tsi;
+PwmOut led(LED_GREEN);
int main() {
pc.printf("Hello!\n");
// By default, no color
green = 1; red = 1, blue = 1;
-
+
+
+
+
+// while (true) {
+// float test= tsi.readPercentage();
+// pc.printf("%f",test);
+// wait(0.1);
+// }
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
@@ -85,7 +99,10 @@
void loop(void) {
// Turn back to no color
green = 1; red = 1, blue = 1;
-
+ float tsiVal = tsi.readPercentage();
+ if (tsiVal > 0) {
+ lastTouch = tsiVal;
+ }
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
@@ -104,111 +121,12 @@
pc.printf(" UID Value: ");
nfc.PrintHex(uid, uidLength);
pc.printf("\n");
+ // We are not actually writing to the card. We just want to know the ID.
+ // Read value associated with ID to a database once we have an SD card...
+ led = 1.0 - readVal;
+ // Would write to database with ID card and lastTouch
+ readVal = lastTouch;
- if (uidLength == 4)
- {
- // We probably have a Mifare Classic card ...
- pc.printf("Seems to be a Mifare Classic card (4 byte UID)\n");
-
- // Now we need to try to authenticate it for read/write access
- // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
- pc.printf("Trying to authenticate block 4 with default KEYA value\n");
- uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-
- // Start with block 4 (the first block of sector 1) since sector 0
- // contains the manufacturer data and it's probably better just
- // to leave it alone unless you know what you're doing
- success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
-
- if (success)
- {
- // Turn colors to indicate which tag
- //green = 0; red = 1;
- uint8_t tag_1 = 250;
- uint8_t tag_2 = 186;
- uint8_t tag_3 = 106;
- uint8_t tag_4 = 10;
- if (uid[0] == tag_1)
- green = 0;
- else if (uid[0] == tag_2)
- red = 0;
- else if (uid[0] == tag_3) {
- green = 0, red = 0;
- } else if (uid[0] == tag_4) {
- red = 0, blue = 0;
- }
-
- pc.printf("Sector 1 (Blocks 4..7) has been authenticated\n");
- uint8_t data[16];
-
- // If you want to write something to block 4 to test with, remove
- // the definition of data above, and uncomment the following lines
- /************************************************************************
- uint8_t data[16] = { 'b', 'e', 'n', ' ', 'z', 'h', 'a', 'n', 'g' };
- success = nfc.mifareclassic_WriteDataBlock (4, data);
- if (success)
- {
- // Data seems to have been read ... spit it out
- pc.printf("Data Written to Block 4:\n\t");
- nfc.PrintHexChar(data, 16);
- pc.printf("\n");
-
- // Wait a bit before reading the card again
- wait(1);
- }
- else
- {
- pc.printf("Ooops ... unable to write the requested block.\n");
- }
- return;
- ************************************************************************/
-
- // Try to read the contents of block 4
- /*success = nfc.mifareclassic_ReadDataBlock(4, data);
-
- if (success)
- {
- // Data seems to have been read ... spit it out
- pc.printf("Reading Block 4:\n\t");
- nfc.PrintHexChar(data, 16);
- pc.printf("\n");
-
- // Wait a bit before reading the card again
- wait(1);
- }
- else
- {
- pc.printf("Ooops ... unable to read the requested block. Try another key?\n");
- }*/
- }
- else
- {
- pc.printf("Ooops ... authentication failed: Try another key?\n");
- }
}
- if (uidLength == 7)
- {
- // We probably have a Mifare Ultralight card ...
- pc.printf("Seems to be a Mifare Ultralight tag (7 byte UID)\n");
-
- // Try to read the first general-purpose user page (#4)
- pc.printf("Reading page 4\n");
- uint8_t data[32];
- success = nfc.mifareultralight_ReadPage (4, data);
- if (success)
- {
- // Data seems to have been read ... spit it out
- nfc.PrintHexChar(data, 4);
- pc.printf("\n");
-
- // Wait a bit before reading the card again
- wait(1);
- }
- else
- {
- pc.printf("Ooops ... unable to read the requested page!?\n");
- }
- }
- }
}
\ No newline at end of file
