compilable code before testing

Dependencies:   4DGL-uLCD-SE EthernetInterface PinDetect mbed-rtos mbed

Revision:
3:03629edd59ff
Parent:
2:50b6517bcae4
Child:
4:5f88215b5bb3
--- a/main.cpp	Thu Oct 22 02:59:40 2015 +0000
+++ b/main.cpp	Thu Oct 22 04:10:33 2015 +0000
@@ -49,7 +49,7 @@
 void pb1_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)) {
     NotePlayer.PlayNote(1200.0,0.15,0.1);
-    myLED1 = !myLED1;
+    //myLED1 = !myLED1;
     Code[CodeCounter] = 1;
     //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
@@ -59,7 +59,7 @@
 void pb2_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)){
     NotePlayer.PlayNote(1200.0,0.15,0.1);
-    myLED2 = !myLED2;
+    //myLED2 = !myLED2;
     Code[CodeCounter] = 2;
     //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
@@ -69,7 +69,7 @@
 void pb3_hit_callback (void) {
     if ((state == IR_sensed) ||(state == Cleared)) {
     NotePlayer.PlayNote(1200.0,0.15,0.5);
-    myLED3 = !myLED3;
+    //myLED3 = !myLED3;
     Code[CodeCounter] = 3;
     //printf("\n  PB: %d\n\r",Code[CodeCounter]);
     CodeCounter++;
@@ -79,7 +79,7 @@
 void pb4_hit_callback (void) {
    if ((state == IR_sensed) ||(state == Cleared)) {
        NotePlayer.PlayNote(1200.0,0.15,0.5);
-       myLED4 = !myLED4;
+       //myLED4 = !myLED4;
         Code[CodeCounter] = 4;
         //printf("\n  PB: %d\n\r",Code[CodeCounter]);
         CodeCounter++;
@@ -101,11 +101,11 @@
 //wave_player waver(&DACout);
 
 
-float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
-                 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
+float note[18]= {1568.0,1396.9,//1244.5//,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
+                 //1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
 };
-float duration[18]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24,
-                     0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0
+float duration[18]= {0.48,0.24,//0.72//,0.48,0.24,0.48,0.24,0.24,0.24,
+                     //0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0
 };
 
 
@@ -124,7 +124,7 @@
         serial.printf("\n  play sound\n\r");
         Consul_Access.release();*/
         mySpeaker.PlaySong(note,duration);
-        Thread::wait(5000); 
+        Thread::wait(1000); 
         }
     }
 }
@@ -140,7 +140,13 @@
                     LCD_Access.lock();
                     uLCD.cls();
                     uLCD.color(WHITE);
-                    uLCD.printf("        ARMED           \n               ");
+                    uLCD.text_width(2); //4X size text
+                    uLCD.text_height(2);
+                    uLCD.printf("  ARMED\r\n");
+                    uLCD.text_width(1); //4X size text
+                    uLCD.text_height(1);
+                    uLCD.printf("\n\nConnected to the  Internet\n");
+                    uLCD.printf("IP Address: \n%s", eth.getIPAddress());
                     LCD_Access.unlock();
                 break;
                 case IR_sensed:
@@ -153,10 +159,10 @@
                     for (int i=30; i>=0; --i) {
                         if (state == IR_sensed) {
                             LCD_Access.lock();
-                            uLCD.text_width(3); //4X size text
-                            uLCD.text_height(3);
+                            uLCD.text_width(4); //4X size text
+                            uLCD.text_height(4);
                             uLCD.color(RED);
-                            uLCD.locate(2,2);
+                            uLCD.locate(1,2);
                             uLCD.printf("%2D",i);                    
                             LCD_Access.unlock();                    
                             Thread::wait(1000);
@@ -178,14 +184,16 @@
                     LCD_Access.lock();
                     uLCD.cls();
                     uLCD.color(RED);
-                    uLCD.printf("\nThis house is being broken into. \nThe athoroties have been informed \n"); 
+                    uLCD.text_width(1.5); //4X size text
+                    uLCD.text_height(1.5);
+                    uLCD.printf("\nALARM IS ON \nText message sent \n"); 
                     LCD_Access.unlock();
                     break;
                 case Cleared: 
                     LCD_Access.lock();
                     uLCD.cls();
                     uLCD.color(GREEN);
-                    uLCD.printf("\nAccess Granted. \n\n"); 
+                    uLCD.printf("\n\nAccess Granted. \n\n"); 
                     LCD_Access.unlock();  
                 break; 
                 }
@@ -207,7 +215,7 @@
                 t.reset();
                 state = Armed;
                 }
-            if (t.read() >= 2) { //wait 5 seconds to make sure that sense someone 
+            if (t.read() >= 3) { //wait 3 seconds to make sure that sense someone 
                 state = IR_sensed; 
                 }
             Thread::wait(1000);
@@ -248,7 +256,7 @@
                 Thread::wait(10);
             }
             for (int i = 100; i >= 0; i--) {
-                RGB_LED( i, i/2, 0);
+                RGB_LED( i, i/3, 0);
                 Thread::wait(10);
             }
         break; 
@@ -268,6 +276,7 @@
             case IR_sensed:
                 if ((Code[0] == 1) &&  (Code[1] == 2) && (Code[2] == 3) && (Code[3] == 4)) {
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
+                    Thread::wait(300);
                     state = Cleared; 
                     CodeCounter = 0;
                     break;
@@ -275,6 +284,7 @@
                 else if ((Code[0] != 0) &&  (Code[1] != 0) && (Code[2] != 0) && (Code[3] != 0)) {
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
                     NotePlayer.PlayNote(200,1,0.5);
+                    Thread::wait(300);
                     state = Alarm_ON; 
                 }
                 Thread::wait(100);
@@ -286,15 +296,16 @@
                 //serial.printf("CC from check: %d%d%d%d\n\r",Code[0],Code[1],Code[2],Code[3]);
                 if ((Code[0] == 4) &&  (Code[1] == 3) && (Code[2] == 2) && (Code[3] == 1)) {
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
-                    Thread::wait(100);
+                    Thread::wait(300);
+                    CodeCounter = 0;
                     state = Armed; 
-                    CodeCounter = 0;
                     break;
                     }
                 else if ((Code[0] != 0) &&  (Code[1] != 0) && (Code[2] != 0) && (Code[3] != 0)) {
                     Code[0] = Code[1] = Code[2] = Code[3] =0;
                     NotePlayer.PlayNote(200,1,0.5);
-                    Thread::wait(100);
+                    CodeCounter = 0;
+                    Thread::wait(300);
                 //state = Alarm_ON; 
                 }
                 Thread::wait(100);
@@ -368,20 +379,22 @@
         switch (state) {
             //state: Armed =0 ,IR_sensed = 1,Second_Step = 2,Cleared = 3, Alarm_ON = 4};
                 case Armed:
-                    Thread::wait(1000); //nothing to do for this thread make space for others
+                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break;
                 case IR_sensed:
+                case Cleared:
                     
                     Thread::wait(500);
+                    while((state == IR_sensed)||(state == Cleared)) {
                     LCD_Access.lock();
 
                     uLCD.line(MidPoint-2*(LineWidth+SpaceWidth), LineHight, MidPoint- 2*SpaceWidth-LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
                     uLCD.line(MidPoint-LineWidth-SpaceWidth, LineHight, MidPoint-SpaceWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
                     uLCD.line(MidPoint+SpaceWidth, LineHight, MidPoint+SpaceWidth+LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
                     uLCD.line(MidPoint+2*SpaceWidth+LineWidth, LineHight, MidPoint+2*(SpaceWidth+LineWidth), LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
-                    LCD_Access.unlock();
-                    while(state == IR_sensed) {
-                        LCD_Access.lock();
+                    //LCD_Access.unlock();
+                    
+                       // LCD_Access.lock();
                         uLCD.locate(5,14);
                         uLCD.text_width(1); //4X size text
                         uLCD.text_height(1);
@@ -390,13 +403,13 @@
                         LCD_Access.unlock();
                     }
                 case Second_Step:
-                    Thread::wait(1000); //nothing to do for this thread make space for others
+                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break; 
-                case Cleared:
-                    Thread::wait(1000); //nothing to do for this thread make space for others
-                break;
+                //case Cleared:
+                //    Thread::wait(1000); //nothing to do for this thread make space for others
+                //break;
                 case Alarm_ON:
-                    Thread::wait(1000); //nothing to do for this thread make space for others
+                    //Thread::wait(1000); //nothing to do for this thread make space for others
                 break;
                 }
         }