แก้ให้แล้ว

Dependencies:   NOKIA_5110 mbed

Fork of Lost-Found_BOX by FRA221:A

Revision:
4:75346bd905c0
Parent:
3:c927196a726f
Child:
5:8e3bd2501b17
--- a/main.cpp	Sun Dec 06 22:51:40 2015 +0000
+++ b/main.cpp	Sun Dec 06 23:22:21 2015 +0000
@@ -16,13 +16,13 @@
 #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"
 DigitalOut LedGreen(LED1);
 DigitalOut spi_address[2] = {SPI_CS,PB_4};
 //Serial connection to PC for output
 Serial pc(SERIAL_TX, SERIAL_RX);
-PwmOut speaker(D3);
-DigitalOut lock(D2);
+Speakers speak(D3);
+DigitalOut lock(PB_13);
 MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 
 void GetID(uint8_t ID[])
@@ -32,35 +32,12 @@
       ID[i] = RfChip.uid.uidByte[i];
     };  
 }
-void speak()
-{
-    speaker.period_ms(1);
-    speaker.write(0.1f);
-    wait(0.2);
-    speaker.write(0);
-}
-void speakRight()
-{
-    speaker.period_ms(1);
-    speaker.write(0.1f);
-    wait(1);
-    speaker.write(0);
-}
-void speakWrong()
-{
-    speaker.period_ms(1);
-    speaker.write(0.1f);
-    wait(0.2);
-    speaker.write(0);
-    wait(0.1);
-    speaker.write(0.1f);
-    wait(0.2);
-    speaker.write(0);
-}
+
 void checkRight()
 {
 }
 int main(void) {
+    pc.baud(115200);
     uint8_t RFID[10];
     int check=0;
     LcdPins myPins;      
@@ -111,7 +88,7 @@
             myLcd.stop();
             check = 0;
             lock = 1;
-            speakRight();
+            speak.speakRight();
             wait(2.5);
             lock = 0;
             continue;
@@ -122,7 +99,7 @@
             myLcd.InitLcd();              
             myLcd.DrawString("Wrong!!  ");   
             myLcd.stop();
-            speakWrong();
+            speak.speakWrong();
             continue;
         }
     }
@@ -139,7 +116,7 @@
     {
       pc.printf(" %X", RfChip.uid.uidByte[i]);
     }
-    speak();
+    speak.speak();
     GetID(RFID);
     lock = 0;
     pc.printf("\n\r");