Sensor de movimiento con bluetooth

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
AndreaC
Date:
Sat Nov 29 22:54:32 2014 +0000
Parent:
0:0a405c6f350d
Commit message:
movimiento

Changed in this revision

movimiento.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/movimiento.cpp	Sat Nov 29 20:17:52 2014 +0000
+++ b/movimiento.cpp	Sat Nov 29 22:54:32 2014 +0000
@@ -6,8 +6,39 @@
 Timer timer;
 int begin, end;
 
+PwmOut buzzer_valor(PTB2);
+
 Serial bt(PTE0, PTE1);
 
+void fBuzzer()
+{ // funcion del buzzer
+    bt.baud(9600);
+    buzzer_valor.period_ms(1); // set PWM period
+    bt.printf("INTRUSO!");
+    while(1)
+    {
+        if(bt.readable())
+        {
+            //valorDIP = switchSistemaSeguridad.read();
+            buzzer_valor = 0.5; //set duty cycle
+            wait(0.3); //hold for beat period
+            buzzer_valor = 0;
+            wait(0.3);
+            
+            /*ledsPrincipales = 1; //set duty cycle
+            wait(0.3); //hold for beat period
+            ledsPrincipales = 0;
+            wait(0.3);*/
+            
+            int blue = bt.getc();
+            if (blue == 'd'){     
+                bt.printf("Sistema Desactivado");
+                return;
+            }
+        }            
+    }
+}
+
 void f_SensorMovimiento()
 {
     timer.start();
@@ -35,17 +66,27 @@
     bt.baud(9600);
     while(1)
     {
+        
+        int val = pinLectura.read();
+        
         if(bt.readable()) //establesco la conexion del bluethooth 
         { 
             char c = bt.getc(); //resive un caracter via bluethoth y lo asigna a una variable 
             //bt.printf("%c\n\r", c);
             
+            if(c == 's')
+            {
+                bt.printf("Sistema Activado");
+                if(val == 0)
+                {
+                    fBuzzer();
+                }
+            }
+            
             if (c == 'm')
             {
                 bt.printf("Iluminacion Automatica Activada\r");
                 while(c != 'v'){
-                
-                    int val = pinLectura.read();
         
                     if (val == 0)
                     {