Test for Parallax-X-Band for detect presence

Dependencies:   Parallax_X-Band

Revision:
0:01f096023c74
--- /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