Punto 2 del TP1: AMI

Dependencies:   mbed

Revision:
0:559e1fcef2f4
Child:
1:4ca7086e337b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 31 14:10:20 2018 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+
+AnalogOut salida(PTE30);
+DigitalOut IN (PTC0);
+Ticker temporizador;
+
+enum {PRE_UNO_POSITIVO, UNO_POSITIVO, PRE_UNO_NEGATIVO, UNO_NEGATIVO};
+
+void maq_AMI(int a);
+void timer (void);
+
+int entrada[16]= {0,1,0,1,1,0,1,0,1,1,1,0,1,0,0,1};
+int estado = PRE_UNO_POSITIVO;
+int n=0;
+int timeout = 0;
+
+int main()
+{
+    temporizador.attach(&timer,0.001);
+    salida = 0.5;
+
+    while(1) {
+        maq_AMI(entrada[n]);
+    }
+}
+
+void maq_AMI(int a)
+{
+    if (n == 18) {
+        salida = 0.5;
+        return;
+    }
+    if(timeout > 0) {
+        return;
+    }
+    IN = entrada[n];
+
+    switch(estado) {
+        default:
+        case PRE_UNO_POSITIVO:
+            salida = 0.5;
+            if(a == 1) {
+                estado = UNO_POSITIVO;
+            }
+            break;
+        case UNO_POSITIVO:
+            salida = 1;
+            if (a == 1) {
+                estado = UNO_NEGATIVO;
+            }
+            if (a == 0) {
+                estado = PRE_UNO_NEGATIVO;
+            }
+            break;
+        case UNO_NEGATIVO:
+            salida = 0;
+            if (a == 1) {
+                estado = UNO_POSITIVO;
+            }
+            if (a == 0) {
+                estado = PRE_UNO_POSITIVO;
+            }
+            break;
+        case PRE_UNO_NEGATIVO:
+            salida = 0.5;
+            if (a == 1) {
+                estado = UNO_NEGATIVO;
+            }
+            break;
+    }
+    timeout = 100;
+    n++;
+}
+
+void timer (void)
+{
+    if (timeout >0)
+        timeout--;
+}
+