A security system that detects the movement of an object in a box using IR distance sensors

Dependencies:   4DGL-uLCD-SE Camera_LS_Y201 SDFileSystem mbed wave_player

Files at this revision

API Documentation at this revision

Comitter:
tdouglas6
Date:
Tue Dec 09 14:53:24 2014 +0000
Parent:
0:a729b4a52c27
Commit message:
Security system that detects the movement of an object in a box.

Changed in this revision

Camera_LS_Y201.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201.lib	Tue Dec 09 14:53:24 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879
--- a/main.cpp	Fri Dec 05 00:33:13 2014 +0000
+++ b/main.cpp	Tue Dec 09 14:53:24 2014 +0000
@@ -4,14 +4,13 @@
 #include "wave_player.h"
 #include "uLCD_4DGL.h"
 
-
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
 Serial device(p13, p14);  // tx, rx
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 //AnalogOut DACout(p18);
 //wave_player waver(&DACout);
 
@@ -21,6 +20,7 @@
 
 uLCD_4DGL uLCD(p28, p27, p11); // create a global lcd object
 
+
 // Create the interrupt receiver object on pin 26
 InterruptIn interrupt(p26);
 // Setup the i2c bus on pins 9 and 10
@@ -34,6 +34,7 @@
 int miss=0;
 int strikes=0;
 
+
 // voice recognition interrupt
 void microInterrupt() {
 //    FILE *alarm;
@@ -53,7 +54,7 @@
         wait(0.2);
     }
     led2=1;
-    while (1) {
+    while (strikes!=3) {
         device.putc('i'); //Start Recognition
         device.putc('B'); //Use Wordset 1 - words
         //Use built-in speaker independent words and listen for words
@@ -66,8 +67,12 @@
                 uLCD.cls();
                 uLCD.locate(1,8);
                 uLCD.printf("\nVOICE COMMAND CORRECT.\n");
+                wait(1);
+                uLCD.cls();
+                uLCD.printf("Silent alarm has been turned off.");
             } else {
                 strikes++;
+                led3=!led3;
 //                waver.play(notaccept);
 //                fclose(notaccept);
 //                waver.play(tryagain);
@@ -96,9 +101,9 @@
 void disarmInterrupt() {
       //create wave file
 //    FILE *alarm;
-//    FILE *password;
+//    FILE *pw=fopen("/sd/wavfiles/notaccept.wav","r");
 //    alarm=fopen("/sd/wavfiles/BurglarAlarm.wav","r");
-//    password=fopen("/sd/wavfiles/pwaccepted.wav","r");
+
     uLCD.cls();
     int i=0;
     int value=mpr121.read(0x00);
@@ -111,9 +116,9 @@
             break;
       }
       
-    uLCD.text_width(4); //4X size text
-    uLCD.text_height(4);
-    uLCD.color(RED);
+    uLCD.text_width(3); //4X size text
+    uLCD.text_height(3);
+    uLCD.color(WHITE);
     uLCD.locate(2,1);
 
     if (i == 0) {
@@ -164,6 +169,8 @@
    
     if (passcode==4) {
         if(miss==0) {
+            led1=1;
+    
             //CHECKPOINT
             uLCD.cls();
             uLCD.text_width(1); //4X size text
@@ -171,8 +178,6 @@
             uLCD.color(GREEN);
             uLCD.locate(1,8);
             uLCD.printf("\nPASSCODE CORRECT.\n");
-//            waver.play(password);
-//            fclose(password);
             wait(1);
             uLCD.cls();
             uLCD.locate(1,2);
@@ -180,6 +185,7 @@
             microInterrupt();
             
         } else {
+            led3=!led3;
 //            uLCD.cls();
 //            uLCD.text_width(1); //4X size text
 //            uLCD.text_height(1);
@@ -187,15 +193,19 @@
 //            uLCD.printf("\nPasscode invalid. Try again\n");
             miss=0;
             passcode=0;
-            strikes++;
-            wait(2);
-            
+            strikes++;            
                         //ALARM GOES OFF
             if(strikes==3) {
+                led1=!led1;
+                led3=!led3;
                 uLCD.text_width(1); //4X size text
                 uLCD.text_height(1);
                 uLCD.locate(1,8);
+                uLCD.color(RED);
                 uLCD.printf("\nToo many invalid passcodes.\n INTRUDER ALERT!\n");
+//                wait(0.2);
+//                waver.play(pw);
+//                fclose(pw);
                 wait(1);
                 uLCD.cls();
                 uLCD.text_width(3); //4X size text
@@ -208,11 +218,10 @@
         }
     }
 } 
+    
 
 int main() {
-//    FILE *alarm;
-//    alarm=fopen("/sd/wavfiles/BurglarAlarm.wav","r");
-    uLCD.printf("WARNING:\nThis security system is currently on. To turn off the alarm...");
+    uLCD.printf("This security system is currently on.");
     wait(3);
     uLCD.cls();
     uLCD.locate(1,2);
@@ -220,15 +229,27 @@
 
     interrupt.fall(&disarmInterrupt);
     interrupt.mode(PullUp);
+//    FILE *alarm = fopen("/sd/wavfiles/notaccept.wav","r");
+    
+//    if(alarm==NULL) {
+//        printf("No file");
+//    }
     
     while (1) {
-        if(s1 > 0.3) {
+        if(s1 > 0.2) {
             led4 = 1;
+            wait(0.5);
         } else {
             //ALARM GOES OFF
             led4 = 0;
+            uLCD.cls();
+            uLCD.text_width(3); //4X size text
+            uLCD.text_height(3);
+            uLCD.locate(0,0);
+            uLCD.printf("Alerting Authorities!");
+//            wait(0.2);
 //            waver.play(alarm);
-//            fclose(alarm);
-        }     
-   }
+//            fclose(alarm);     
+        }
+    }
 }