Santiago Muñoz Tamayo / Mbed 2 deprecated Lavadora

Dependencies:   DebouncedIn PinDetect Pulse mbed

Files at this revision

API Documentation at this revision

Comitter:
sago104
Date:
Mon May 23 20:07:21 2016 +0000
Child:
1:8171657a1bcb
Commit message:
First version

Changed in this revision

DebouncedIn.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
Pulse.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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.lib	Mon May 23 20:07:21 2016 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/cmorab/code/DebouncedIn/#dc1131de43e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Mon May 23 20:07:21 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pulse.lib	Mon May 23 20:07:21 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/NickRyder/code/Pulse/#fb79a4637a64
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 23 20:07:21 2016 +0000
@@ -0,0 +1,131 @@
+#include "mbed.h"
+#include <Pulse.h>
+#include "DebouncedIn.h"
+#define off 1
+#define on 0
+
+Serial pc(USBTX,USBRX); // Abre puerto serial
+Serial GSM(PTE0,PTE1);
+
+DigitalOut LedVerde(LED2,off);
+DigitalOut LedRojo(LED1,off);
+DigitalOut LedAzul(LED3,off);
+DigitalOut bomba(PTA17); // Pin para activar la bomba
+PulseInOut pulseIn(PTD4); // Generamos los pulsos
+
+DebouncedIn levelBalde(PTC17); // Sensor de nivel del balde
+DebouncedIn levelTanque(PTC16); // Sensor de nivel en el tanque de almacenamiento
+AnalogIn input(PTC2);
+
+int cPulsos; // Cuenta los pulsos
+int limBmax = 5; // Límite de agua máximo en el balde. 50 cm.
+//int limBmin = 1; // Límite de agua mínimo en el balde. 10 cm
+int i, j, k, m, num;
+
+void pulsos() // Generación de pulsos
+{
+    pulseIn.write_us(0, 3000000);  // 3 segundos tiempo bajo
+    cPulsos++; // Cuenta cuando hay un flanco de bajada
+    pulseIn.write_us(1, 1000000); // 1 segundo arriba
+}
+
+void sendData(float input){
+    wait(1);
+       num = input*1000;      //agrando el numero de cero a mil
+       GSM.putc(num);
+       pc.printf("num %d,data %f \r\n", num, input);
+       if(num < 256){           //debo generar dos casos a APP inventor solo me recibe hex asi: 0xhhhh (4 cifras)    
+           GSM.putc(0);     //si el numero es hasta 255 se le ponen dos ceros adelante a la secuencia de bits
+           GSM.putc(i);     //luego la cifra menos significativa
+           pc.printf("Cero: %d\r\n", 0);
+           pc.printf("m: %d\r\n", m);
+       }
+       if(num >255){          //pero si es mayor a 255 las cifras deben ser convertidas a un hex de dos bytes de la siguiente forma   
+          j = num/256;       //calculo la cifra mas significativa
+           k = num - j*256;     //calculo la cifra menos significativa
+           GSM.putc(j);   //las envio a la usart para que se las ponga al modulo bluetooth y la lleve al android
+           GSM.putc(k);   //mas significativa primero, menos despues si no no funciona!!! y con la orden PUTC solo asi le envia binarios
+           pc.printf("j: %d\r\n", j);
+           pc.printf("k: %d\r\n", k);
+       }
+    }
+
+int main()
+{
+    GSM.baud(9600);   // asigno baudios y configuro puerto serie de la usart
+    GSM.format(8,Serial::None,1);
+    wait(1);
+    pc.printf("Ahorrador de agua\r\n");
+    pc.printf("El programa se esta iniciando\r\n");
+    wait(1);
+    LedVerde = on;
+    wait(1);
+    LedVerde = off;
+    wait(1);
+    LedRojo = on;
+    wait(1);
+    LedRojo = off;
+    wait(1);
+    LedAzul = on;
+    wait(1);
+    LedAzul = off;
+    wait(1);
+
+
+    // Inicia el ciclo
+    while(1) {
+waitPulse: // Acá leeríamos los pulsos
+        for(i = 0; i <= 3; i++) {
+            pulsos();
+            pc.printf("Esperando senal de flujo...\r\n");
+            if (cPulsos == 3) {
+                goto seguir;
+            } else goto waitPulse;
+        }
+seguir:
+        cPulsos = 0;
+        pc.printf("\r\n");
+        pc.printf("El programa ha iniciado.\r\n");
+        LedVerde = on;
+        wait(1);
+        LedVerde = off;
+        //printf("Accionamos la bomba.\n");
+        //LedAzul = on; // Puede ser la bomba
+        goto llenarBalde;
+
+llenarBalde: // Llenar balde donde está la bomba
+        i = 0;
+        while(i <= limBmax) { // Ciclo para llenar el balde
+            if(i == limBmax) {
+                pc.printf("El balde de almacenamiento se ha llenado. Se inicia el bombeo.\r\n");
+                goto llenarTanque;
+                
+            } else {
+                pc.printf("Llenando balde\r\n");
+                wait(1);
+                i++;
+            }
+        }
+
+llenarTanque:
+        float limTmax = 1;
+        for(float l = 0; l <= limTmax; l += 0.016666667) {
+            if (l == limTmax) { // Significa que se ha llenado el tanque y se debe alertar.
+                pc.printf("Se ha llenado el tanque. Abra la valvula del desague.\r\n");
+                goto final;
+            } else {
+                sendData(l); // Enviar dato a la aplicación de llenado de tanque
+            }
+        }
+final:
+        pc.printf("Salir.");
+        while(1) {
+            LedRojo = on;
+            wait(1);
+            LedRojo = off;
+            wait(1);
+        }
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 23 20:07:21 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file