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

Dependencies:   mbed

main.cpp

Committer:
Jamess
Date:
2015-05-28
Revision:
0:59b7da6bb864

File content as of revision 0:59b7da6bb864:

/*****************************************************************/
/*               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

/************************************/