Pedro Colla / Mbed 2 deprecated CTo_VyV_TPAlarma

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pcolla
Date:
Sat Nov 16 00:48:19 2013 +0000
Commit message:
alarma VyV

Changed in this revision

Armar.cpp Show annotated file Show diff for this revision Revisions of this file
Config.cpp Show annotated file Show diff for this revision Revisions of this file
Filtro.cpp Show annotated file Show diff for this revision Revisions of this file
KeepAlive.cpp Show annotated file Show diff for this revision Revisions of this file
LED.cpp Show annotated file Show diff for this revision Revisions of this file
LuzDisparo.cpp Show annotated file Show diff for this revision Revisions of this file
Pip.cpp Show annotated file Show diff for this revision Revisions of this file
SensorAnalogico.cpp Show annotated file Show diff for this revision Revisions of this file
SensorDigital.cpp Show annotated file Show diff for this revision Revisions of this file
Sirena.cpp Show annotated file Show diff for this revision Revisions of this file
Test.cpp Show annotated file Show diff for this revision Revisions of this file
alarma.h 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Armar.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,33 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void Armar(void){
+    Pip(1);                                     //Armando.
+    for(i=0;i<delayFactory;i++){
+        KeepAlive();
+        wait(0.8);                              //Con KeepAlive es 1 seg por vuelta.                  
+    }
+    Buzzer = 1;                                 //Armada.
+    wait(1);
+    Buzzer = 0;         
+    while(Pulsador == false){                    //Armada    /////
+        An = SensorAnalogico();                                 //
+        Di = SensorDigital();                                   //
+        KeepAlive();                                            //
+        if((An == 2)||(Di == false)){                           //
+            while(Pulsador == false){            //Dsparada     //
+                Sirena(delaySirena);                        //  //
+                LuzDisparo(delayLuz);                       //  //
+            }                                    /////////////  //
+            wait(1);                                            //
+            Pip(2);                                             //
+            return;                                             //
+        }                                                       //
+    }                                            /////////////////
+    Pip(2);
+    return;
+}
+
+        
+   
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Config.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,72 @@
+#include "alarma.h"
+#include "mbed.h"
+
+int contador = 0;
+
+void Config(void){
+    if(Prog == 1){                              //Bandera para que entre a programacion solo después de un reseteo.
+        while(Pulsador != false);               //Espero que se suelte el pulsador.                                   
+        Pip(3);
+        while(true){
+            if(contador >= 25){                 //Si el tiempo llega a 5 seg...
+                Pip(3);
+                contador = 0;
+                break;
+            }
+            contador = 0;
+            while(Pulsador != true)            //Aguardo a que se presione el pulsador.
+                KeepAlive();
+            wait(0.05);
+            delaySirena++;
+            Pip(1);
+            if(delaySirena >= 10)
+                delaySirena = 1;
+            while(Pulsador != false){           //Espero que se suelte el pulsador. 
+                contador++;
+                KeepAlive();                    //0.2 segundos
+            }               
+        }
+        while(true){
+            if(contador >= 25){
+                Pip(3);
+                contador = 0;
+                break;
+            }
+            contador = 0;
+            while(Pulsador != true)
+                KeepAlive();
+            wait(0.05);
+            delayLuz++;
+            Pip(1);
+            if(delayLuz >= 10)
+                delayLuz = 1;
+            while(Pulsador != false){
+                contador++;
+                KeepAlive();                    //0.2 segundos
+            }               
+        }
+        while(true){
+            if(contador >= 25){
+                Buzzer = 1;
+                wait(1);
+                Buzzer = 0;
+                wait(1);
+                contador = 0;          
+                return;
+            }
+            contador = 0;
+            while(Pulsador != true)
+                KeepAlive();
+            wait(0.05);
+            delayFactory = delayFactory + 1;
+            Pip(1);
+            if(delayFactory >= 5)
+                delayFactory = 2;
+            while(Pulsador != false){
+                contador++;
+                KeepAlive();                    //0.2 segundos
+            }               
+        }
+    }
+}
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Filtro.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,17 @@
+#include "alarma.h"
+#include "mbed.h"
+
+float   smoother = 0;
+float   f1 = 0;
+float   f2 = 0;
+float   f3 = 0;
+
+float Filtro(void){
+    f1 = Valor;
+    wait(0.2);
+    f2 = Valor;
+    wait(0.2);
+    f3 = Valor;
+    smoother = (f1 + f2 + f3)/3;
+    return smoother;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeepAlive.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,10 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void KeepAlive(void){
+    Alive = 1;
+    wait(0.05);
+    Alive = 0;
+    wait(0.15);
+    return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LED.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,16 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void LED(int a){
+    if(a == 1){
+        Indicador = 1;
+        wait(0.2);
+        Indicador = 0;
+        wait(0.2);
+    }
+    else if(a == 2)
+        Indicador = 1;
+    else
+        Indicador = 0;
+    return;
+}   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LuzDisparo.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,15 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void LuzDisparo(int Dl){
+    Luz = 0;
+    for(i=0;i<Dl;i++){               //0.2 seg. por ciclo de for
+        KeepAlive();     
+        if(Pulsador == 1){
+            Luz = 0;
+            return; 
+        }          
+    }                  
+    Luz = 1;
+    return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pip.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,12 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void Pip(int p){
+    for(i=0;i<p;i++){
+        Buzzer = 1;                                     
+        wait(0.1);                                      
+        Buzzer = 0;                                     
+        wait(0.1);
+    }
+return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorAnalogico.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,17 @@
+#include "alarma.h"
+#include "mbed.h"
+
+float   lectura = 0;
+float   referencia = 0;
+
+int SensorAnalogico(void){
+    lectura = Filtro();
+    referencia = Ref;                       //Pot1
+    if(lectura <= referencia)
+        AStatus = 1;
+    if(lectura > referencia)
+        AStatus = 2;
+    if((lectura >= 0)&&(lectura <0.1))
+        AStatus = 0;
+    return AStatus;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorDigital.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,7 @@
+#include "alarma.h"
+#include "mbed.h"
+
+int SensorDigital(void){
+    DStatus = Estado;
+return DStatus;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sirena.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,15 @@
+#include "alarma.h"
+#include "mbed.h"
+
+void Sirena(int Ds){
+    Buzzer = 1;
+    for(i=0;i<Ds;i++){               //0.2 seg. por ciclo de for
+        KeepAlive();
+        if(Pulsador == 1){
+            Buzzer = 0;
+            return;
+        }
+    }
+    Buzzer = 0;
+    return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Test.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,26 @@
+#include "alarma.h"
+#include "mbed.h"
+
+int     Test1 = 0;
+int     Test2 = 0;
+int     j = 0;
+int     resultado = 0;
+
+int Test(void){
+    Auto = 1;                               //Luego de un test se arma automáticamente.
+    while(Pulsador != 0){
+        LED(Titila);
+        KeepAlive();
+    } 
+    Test1 = SensorAnalogico();              //Sistema testea
+    Test2 = SensorDigital();                //Sistema testea
+    for(j=0;j<2;j++)
+        LED(Titila);                        //Usuario testea
+    LuzDisparo(delayLuz);                   //Usuario testea
+    Sirena(testSirena);                     //Usuario testea
+    if((Test1 != 1) || (Test2 != true))
+        resultado = 0;
+    else
+        resultado = 1;
+    return resultado; 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/alarma.h	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,125 @@
+#ifndef ALARMA_H
+#define ALARMA_H
+
+#include "mbed.h"
+
+extern AnalogIn    Ref;                   //Pot 1
+extern DigitalIn   Pulsador;              //Joystick Center
+extern DigitalOut  Buzzer;                //Sirena
+extern AnalogIn    Valor;                 //Pot 2 (Sensor Analogo)
+extern DigitalOut  Alive;                //KeepAlive signal
+extern DigitalOut  Indicador;            //LED de encendido
+extern DigitalOut  Luz;                   //RGB red
+extern DigitalIn   Estado;                //Sensor Digital
+
+extern int     i;
+extern int     j;
+extern int     Titila;
+extern int     On;
+extern int     Off;
+extern bool    check;
+extern bool    testResult;
+extern int     delaySirena;              //Factory configuration.           
+extern int     testSirena;
+extern int     delayLuz;                 //Factory configuration.
+extern int     delayFactory;               //Factory configuration.
+extern int     AStatus;
+extern int     DStatus;
+extern int     An;
+extern int     Di;
+extern int     Prog;
+extern int     Auto;
+
+
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    int Test(void);
+
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void LED(int a);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void KeepAlive(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void Config(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void Armar(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    int SensorAnalogico(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    int SensorDigital(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void Sirena(int Ds);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void LuzDisparo(int Dl);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    float Filtro(void);
+    
+/** 
+     *
+     * 
+     * 
+     * 
+     */
+    void Pip(int p);
+    
+#endif
+    
+    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,79 @@
+#include "mbed.h"
+#include "alarma.h"
+
+AnalogIn    Ref(p19);                   //Pot 1
+DigitalIn   Pulsador(p14);              //Joystick Center
+DigitalOut  Buzzer(p29);                //Sirena
+AnalogIn    Valor(p20);                 //Pot 2 (Sensor Analogo)
+DigitalOut  Alive(LED2);                //KeepAlive signal
+DigitalOut  Indicador(LED1);            //LED de encendido
+DigitalOut  Luz(p23);                   //RGB red
+DigitalIn   Estado(p21);                //Sensor Digital
+
+int     i=0;
+int     Titila = 1;
+int     On = 2;
+int     Off = 3;
+bool    check = true;
+bool    testResult = false;
+int     delaySirena = 1;              //Factory configuration.           
+int     testSirena = 1;
+int     delayLuz = 1;                 //Factory configuration.
+int     delayFactory = 2;               //Factory configuration.
+int     AStatus = 0;
+int     DStatus = 0;
+int     An = 0;
+int     Di = 0;
+int     Prog;
+int     Auto = 1;                       //Armado automático al encender.
+
+int main() {
+    Luz = 1;
+    Prog = 1;
+    Auto = 1;
+    while(true){
+        if(check == true)
+            testResult = Test();
+        while(testResult == 0){
+            Luz = 1;
+            LED(Titila);
+            KeepAlive();
+            if(Pulsador == true){
+                wait(5);
+                if(Pulsador == true){
+                    check = 1;              //Test habilitado.
+                    break;
+                }
+            }
+        }
+        while(testResult){
+            Luz = 1;
+            if(Pulsador == true){
+                wait(5);
+                if(Pulsador == true){
+                    Config();               //Modo programación en Fábrica.
+                }
+            }
+            Prog = 0;                       //Deshabilito modo programación hasta resetear.
+            LED(On);
+            while((Pulsador == false)&&(Auto != 1)){       //Esperando armado.
+                KeepAlive();
+            }  
+            Auto = 0;  
+            wait(0.05);
+            for(i=0;i<10;i++){              //Pulsador presionado > 5s => Test().
+                if(Pulsador){
+                    wait(0.5);              
+                    check = true;           //Test habilitado.
+                }
+                else {   
+                    check = false;
+                    Armar();
+                    break;
+                }
+            }
+            if(check == true)
+                break;                      //Go to Test.
+        }              
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 16 00:48:19 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file