Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ezebrizzio
Date:
Wed Jul 15 22:13:23 2020 +0000
Commit message:
ejemplo maquina de estados led

Changed in this revision

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
diff -r 000000000000 -r 62c9a355c139 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 15 22:13:23 2020 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+
+//declaracion de estados
+#define APAGADO 0
+#define ENCENDIDO 1
+
+//Entradas o eventos del sistema
+unsigned char C = 0;
+
+//Interrupcion recurrente
+Ticker nombre_del_ticker;
+
+//Salida del sistema
+DigitalOut led_rojo(LED1);
+
+//funcion con llamado recurrente
+void funcion (){
+    C++; //C = C + 1; C += C;
+}
+
+void maquina_estado(){
+    static unsigned char estado = APAGADO;
+
+    switch(estado)
+    {
+        default:
+            estado = APAGADO;
+            break;
+            
+        case APAGADO:
+            //entrada
+            if( C > 2 )
+            {
+                //salidas
+                led_rojo = 0;   //pin a GND = LED ENCENDIDO
+                C = 0;
+                //transicion
+                estado = ENCENDIDO;
+        
+            }        
+            break;
+            
+        case ENCENDIDO:
+            //entrada
+            if( C > 3 )
+            {
+                //salidas
+                led_rojo = 1;   //pin a VCC = LED APAGADO
+                C = 0;
+                //transicion
+                estado = APAGADO;
+        
+            }        
+            break;
+    }
+}
+
+int main() {
+    //Inicializaciones
+    nombre_del_ticker.attach(&funcion, 1.0);
+    
+    //lazo o loop infinito
+    while(1){
+        maquina_estado();
+    }
+}
diff -r 000000000000 -r 62c9a355c139 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 15 22:13:23 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file