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 /* Switch|Case */ 00004 /*****************************************************************/ 00005 00006 // Librarys: 00007 #include "mbed.h" 00008 00009 // Configuration: 00010 DigitalOut led(LED1); 00011 Serial pc(USBTX,USBRX); 00012 00013 //Functions 00014 00015 00016 int main(){ 00017 /************STATES**************/ 00018 enum states{ 00019 LED_OF_1S, 00020 LED_ON_2S, 00021 LED_OF_3S, 00022 LED_ON_4S 00023 }; 00024 enum states state = LED_OF_1S; 00025 while(1){ 00026 switch(state){ 00027 case LED_OF_1S: 00028 00029 //Led off for 1 second: 00030 led=0; 00031 pc.printf("LED_OF"); 00032 wait(1); 00033 state = LED_ON_2S; 00034 00035 break; 00036 case LED_ON_2S: 00037 00038 //Led on for 2 seconds: 00039 led=1; 00040 pc.printf("LED_ON"); 00041 wait(2); 00042 state = LED_OF_3S; 00043 00044 break; 00045 case LED_OF_3S: 00046 00047 //Led off for 3 seconds: 00048 led=0; 00049 pc.printf("LED_OF"); 00050 wait(3); 00051 state = LED_ON_4S; 00052 break; 00053 case LED_ON_4S: 00054 00055 //Led on for 4 seconds: 00056 led=1; 00057 pc.printf("LED_ON"); 00058 wait(4); 00059 state = LED_OF_1S; 00060 break; 00061 } 00062 } 00063 } 00064
Generated on Thu Jul 14 2022 21:50:39 by
1.7.2