Examen / Mbed 2 deprecated MASTER_EXAMEN

Dependencies:   mbed

Revision:
1:b4442f77d497
Parent:
0:dd79e9efee0d
diff -r dd79e9efee0d -r b4442f77d497 main.cpp
--- a/main.cpp	Tue Dec 22 10:52:46 2020 +0000
+++ b/main.cpp	Mon Dec 20 21:37:50 2021 +0000
@@ -3,19 +3,79 @@
 
 AnalogIn adc_temp(ADC_TEMP);
 
-enum estados {estadoUno, estadoDos} estado;
+enum estados {inicio, esperandopulso, mostrartemp, esperandopulsodos   } estado;
 
-const float         AVG_SLOPE   = 4.3E-03;      
-const float         V30         = 1.43;   
+const float         AVG_SLOPE   = 4.3E-03;
+const float         V30         = 1.43;
 
 DigitalOut led(LED1);
 DigitalIn  boton(USER_BUTTON);
+float temperatura;
+float mediatemp;
+int contador;
+Timer t;
+
+void estadoinicio() {
+    if (boton ==1)
+    {
+        estado = esperandopulso;
+    }
+}
+
+void estadoesperandopulso()
+{
+    if (boton==0) {
+        estado = mostrartemp;
+        t.reset();
+    }
+}
+
+void estadomostrartemp()
+{
+    if (t.read()>4.0) {
+        printf("Mostrar la temperatura media %f\n", mediatemp/contador);
+        printf("Mostrar el contador %d\n", contador);
+        mediatemp = 0;
+        contador = 0;
+        estado = inicio;
+
+    } else if (boton==1) {
+        temperatura= (V30-adc_temp.read()*3.3)/ AVG_SLOPE + 30; // con el plus ese se van sumando todos los valores de la temperatura calculada
+        mediatemp+= temperatura;
+        contador++;
+        printf("La temperatura es de %f\n", temperatura);
+        estado= esperandopulsodos;
+    }
+}
+
+void estadoesperandopulsodos()
+{
+    if (t.read ()<0.5 && boton ==0) {
+        led = !led;
+        estado = inicio;
+    } else if (t.read()>0.5) {
+        estado= inicio;
+    }
+}
 
 int main()
 {
-   estado=estadoUno;
-   
+    estado=inicio;
+    t.start();
     while(1) {
-      
+        switch (estado) {
+            case inicio:
+                estadoinicio();
+                break;
+            case esperandopulso:
+                estadoesperandopulso();
+                break;
+            case mostrartemp:
+                estadomostrartemp();
+                break;
+            case esperandopulsodos:
+                estadoesperandopulsodos();
+                break;
+        }
     }
 }