![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
แก้ให้แล้ว
Dependencies: NOKIA_5110 mbed
Fork of Lost-Found_BOX by
main.cpp
- Committer:
- mustwillza
- Date:
- 2015-12-07
- Revision:
- 7:725f5fb7e3a3
- Parent:
- 6:6635082215c7
- Child:
- 8:e683edc8a530
File content as of revision 7:725f5fb7e3a3:
//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 //Connect as follows: //RFID pins -> Nucleo header CN5 (Arduino-compatible header) //---------------------------------------- //RFID IRQ=pin5 -> Not used. Leave open //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 SlaveSelect //RFID RST=pin7 -> Nucleo =PA_9=D8 //3.3V and Gnd to the respective pins #include "mbed.h" #include "MFRC522.h" #include "NOKIA_5110.h" // Nucleo Pin for MFRC522 reset (pick another D pin if you need D8) #define MF_RESET D9 #include "speaker.h" #include "myESP.h" #include "myRFID.h" #include "myLCD4884.h" DigitalOut LedGreen(LED1); DigitalOut spi_address[2] = {SPI_CS,PB_4}; //Serial connection to PC for output Serial esp(D8, D2); //tx rx Serial pc(SERIAL_TX, SERIAL_RX); Speakers speak(D3); DigitalOut lock(PB_13); MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); char buffers[5]={'\0'}; char IDs[17]={'\0'}; void wifiInitial(){ pc.baud(115200); esp.baud(9600); string ssid = "1544_2G"; string pass = "fiborobot" ; if(setupESP(ssid,pass) == 1) { pc.printf("System connected to %s with %s as password\n",ssid.c_str(),pass.c_str()); pc.printf("System Initialized :: ESP8266 Module Ready!\n"); wait(2); } } int main(void) { // Init. LCD Pin LcdPins myPins; myPins.sce = PB_4; //D5 ActiveLow SlaveSelect myPins.rst = PB_10; //D6 myPins.dc = PA_8; //D7 myPins.mosi = PA_7; //SPI_MOSI; myPins.miso = NC; myPins.sclk = PA_5; //SPI_SCK; // Init. LCD Chip NokiaLcd myLcd( myPins ); myLcd.InitLcd(); // LCD is reset and DDRAM is cleared myLcd.DrawString("System Initializing..."); myLcd.stop(); // Init. esp8266 wifiInitial(); char name[20]; char sid[20]; char tel[10]; char stat_uid[3]; // Init.RFID Variable uint8_t RFID[10]; int checker = 0; int checks = 0; int mode = 0; int submode = 0; pc.printf("starting...\n"); // Init. RC522 Chip RfChip.PCD_Init(); pc.printf("Begin RFID!\n"); /* ===== System Initialized ===== */ myLcd.InitLcd(); myLcd.DrawString("Welcome to LOST & FOUND BOX V.1"); myLcd.stop(); getStatus("192.168.1.88","/l-f-box/getdata.php?check=1",stat_uid); if(stat_uid[0] > 0){ mode = 0; //It have an item }else{ mode = 1; //Doesn't have an item } while(mode == 0){ if(submode == 0){ myLcd.InitLcd(); myLcd.DrawString("PLEASE TAP A CARD"); myLcd.stop(); submode++; } if(submode == 1){ if ( ! RfChip.PICC_IsNewCardPresent()) { wait_ms(500); continue; } // Select one of the cards if ( ! RfChip.PICC_ReadCardSerial()) { wait_ms(500); continue; } speak.speak(); submode ++; } if(submode == 2){ wait(0.5); myLcd.InitLcd(); myLcd.DrawString("WAITING..."); myLcd.stop(); GetID(RFID); getDataHTTP("192.168.1.88","/l-f-box/getdata.php?rfid=",IDs,sid,name,tel); submode ++; } if(submode == 3){ wait(0.5); myLcd.InitLcd(); myLcd.DrawString("NAME : "); myLcd.DrawString(name); myLcd.SetXY(0,1); myLcd.DrawString("TEL : "); myLcd.DrawString(tel); myLcd.stop(); } } /* while (true) { LedGreen = 1; // Look for new cards if ( ! RfChip.PICC_IsNewCardPresent()) { wait_ms(500); continue; } // Select one of the cards if ( ! RfChip.PICC_ReadCardSerial()) { wait_ms(500); continue; } LedGreen = 0; myLcd.InitLcd(); myLcd.DrawString("Ready"); myLcd.stop(); checker = check(RFID); if(checks == 1) { if (checker == 1) { pc.printf("Right\n"); myLcd.InitLcd(); myLcd.DrawString("Right"); myLcd.stop(); checks = 0; speak.speakRight(); strcpy(IDs,""); continue; } else { pc.printf("Wrong!!\n"); myLcd.InitLcd(); myLcd.DrawString("Wrong!!"); myLcd.stop(); speak.speakWrong(); continue; } } // Print Card UID pc.printf("Card UID: "); for (uint8_t i = 0; i < RfChip.uid.size; i++) { pc.printf(" %X", RfChip.uid.uidByte[i]); } checker = check(RFID); speak.speak(); GetID(RFID); lock = 0; pc.printf("\n\r"); wait_ms(1000); checks = 1; } */ }