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.
Diff: main.cpp
- Revision:
- 3:157e0f68b775
- Parent:
- 2:a0c7513fb634
diff -r a0c7513fb634 -r 157e0f68b775 main.cpp
--- a/main.cpp Fri Jun 06 03:04:48 2014 +0000
+++ b/main.cpp Tue Jan 22 22:22:11 2019 +0000
@@ -1,3 +1,4 @@
+
//Test of cheap 13.56 Mhz RFID-RC522 module from eBay
//This code is based on Martin Olejar's MFRC522 library. Minimal changes
//Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
@@ -15,26 +16,29 @@
#include "mbed.h"
#include "MFRC522.h"
-
+#include "Servo.h"
// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
#define MF_RESET D8
-
-DigitalOut LedGreen(LED1);
-
+#define PWMA PC_8
//Serial connection to PC for output
Serial pc(SERIAL_TX, SERIAL_RX);
-
+DigitalOut green(D7);
+DigitalOut red(D6);
MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+uint8_t card1=0x20;
+uint8_t card2=0x82;
+uint8_t card3=0xBF;
+uint8_t card4=0x4F;
+PwmOut mypwm(PWMA);
+int main(void) {red=0;
+ volatile float speed_value = 0.5;
-int main(void) {
+ Servo myservo(D2);
pc.printf("starting...\n");
-
// Init. RC522 Chip
RfChip.PCD_Init();
-
while (true) {
- LedGreen = 1;
-
+ red=0;
// Look for new cards
if ( ! RfChip.PICC_IsNewCardPresent())
{
@@ -48,17 +52,25 @@
wait_ms(500);
continue;
}
-
- LedGreen = 0;
-
// Print Card UID
pc.printf("Card UID: ");
for (uint8_t i = 0; i < RfChip.uid.size; i++)
- {
- pc.printf(" %X02", RfChip.uid.uidByte[i]);
+ {pc.printf("%d%",i);
+ pc.printf(" %X02", RfChip.uid.uidByte[i]);
}
pc.printf("\n\r");
-
+ if((RfChip.uid.uidByte[0]==card1)&&(RfChip.uid.uidByte[1]==card2)&&(RfChip.uid.uidByte[2]==card3)&&(RfChip.uid.uidByte[3]==card4))
+{pc.printf("\nhello");
+mypwm.pulsewidth(90);
+green=1;
+myservo=90;
+wait_ms(3000);
+myservo=-90;
+green=0;
+red=0;
+}else {mypwm.pulsewidth(-90);
+green=0;
+red=1;}
// Print Card type
uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));