Test for Parallax-X-Band for detect presence

Dependencies:   Parallax_X-Band

Files at this revision

API Documentation at this revision

Comitter:
jpernav198
Date:
Sun May 31 14:01:52 2020 +0000
Commit message:
Test of Parallax_X-Band for detect presence

Changed in this revision

Parallax_X-Band.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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 01f096023c74 Parallax_X-Band.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Parallax_X-Band.lib	Sun May 31 14:01:52 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/ottaviano3/code/Parallax_X-Band/#9cfc7b541791
diff -r 000000000000 -r 01f096023c74 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 31 14:01:52 2020 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "Parallax_X-Band.h"
+
+Serial pc(USBTX, USBRX);
+Timer t;
+
+xband myxband(PD_10, PD_11);
+
+int main(){
+    //Habilitamos un temporizador para saber el instante de la alarma
+    t.start();    
+    
+    // Habilita el sensor
+    myxband.enable(true);
+    
+    // Variable a calcular la velocidad de estado.
+    float velocity;
+    
+    //Establecemos el umbral
+    float umbral = 1.0;
+    
+    //Establecemos una variable que indica comienzo pues
+    //No podemos comparar la velocidad actual con la antigua
+    //Si no hay valor antiguo alguno
+    bool comienzo = true;
+
+    while(1) {        
+        
+        //Se comprueba si hay un nuevo valor de velocidad
+        while (myxband.velocityack() == true) {
+            
+            if(comienzo){
+                velocity = myxband;
+                comienzo = false;
+            }
+            else{
+                //Se comprueba la velocidad actual frente a la antigua. 
+                //Si supera cierto umbral se considera alerta
+                
+                if( myxband - velocity > umbral)
+                    pc.printf("ALERTA: Se detecta intruso en el instante %f\n",t.read());
+                                    
+                velocity = myxband;
+            }
+
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 01f096023c74 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun May 31 14:01:52 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9