Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /*****************************************************************/ 00002 /* How to use State Machines in C */ 00003 /* If | Else */ 00004 /*****************************************************************/ 00005 00006 //Librarys: 00007 #include "mbed.h" 00008 00009 //Outputs: 00010 DigitalOut red(LED1); 00011 DigitalOut green(LED2); 00012 DigitalOut blue(LED3); 00013 00014 //Functions: 00015 00016 int main() { 00017 00018 /**************VARIABLES**************/ 00019 enum states{ 00020 LED_GREEN, 00021 LED_BLUE, 00022 LED_RED 00023 }; 00024 enum states state = LED_GREEN; 00025 00026 /***************ESTADOS***************/ 00027 00028 while(1){ 00029 if (state == LED_GREEN){ 00030 00031 green=1; 00032 blue=0; 00033 red=0; 00034 state = LED_BLUE; 00035 wait(1); 00036 00037 }else if(state == LED_BLUE){ 00038 00039 green=0; 00040 blue=1; 00041 red=0; 00042 state = LED_RED; 00043 wait(1); 00044 00045 }else if(state == LED_RED){ 00046 00047 green=0; 00048 blue=0; 00049 red=1; 00050 state = LED_GREEN; 00051 wait(1); 00052 00053 } 00054 00055 }//end of while 00056 }//end of main 00057 00058 /************************************/
Generated on Wed Aug 3 2022 07:02:03 by
1.7.2