This program uses a state machine with an if|else. Just an exercise.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Jamess
Date:
Thu May 28 18:05:21 2015 +0000
Commit message:
First Example in how to use state machines in c. Using if|else;

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 59b7da6bb864 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 28 18:05:21 2015 +0000
@@ -0,0 +1,58 @@
+/*****************************************************************/
+/*               How to use State Machines in C                  */
+/*                          If | Else                            */
+/*****************************************************************/
+
+//Librarys:
+#include "mbed.h"
+
+//Outputs:
+DigitalOut red(LED1);
+DigitalOut green(LED2);
+DigitalOut blue(LED3);
+
+//Functions:
+
+int main() {
+    
+/**************VARIABLES**************/
+    enum states{
+        LED_GREEN,
+        LED_BLUE,
+        LED_RED   
+        };
+    enum states state = LED_GREEN;
+    
+/***************ESTADOS***************/ 
+
+while(1){   
+    if (state == LED_GREEN){
+        
+    green=1;        
+    blue=0; 
+    red=0;  
+    state = LED_BLUE;
+    wait(1);
+        
+    }else if(state == LED_BLUE){
+        
+    green=0;
+    blue=1;
+    red=0;
+    state = LED_RED;
+    wait(1);
+        
+    }else if(state == LED_RED){
+        
+    green=0;
+    blue=0;
+    red=1;
+    state = LED_GREEN;
+    wait(1);
+    
+    }
+    
+}//end of while
+}//end of main
+
+/************************************/
diff -r 000000000000 -r 59b7da6bb864 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 28 18:05:21 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file