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 00011 DigitalOut myled(LED1); 00012 Serial pc(USBTX,USBRX); 00013 00014 //Functions: 00015 void SendThings(void); // Sends Something to the computer 00016 void LedON(void); // Turns RED LED ON 00017 void LedOF(void); // Turns RED LED OFF 00018 void PrepThings(void); // Prepares Something 00019 //Function Pointer: 00020 void (*state)()=SendThings;; 00021 00022 00023 int main() { 00024 00025 //State Machine 00026 while(1) { 00027 (*state)(); 00028 wait(1); 00029 } 00030 } 00031 void SendThings(void){ 00032 pc.printf("Sedingthings"); 00033 state=LedON; 00034 } 00035 void LedON(void){ 00036 pc.printf("ON"); 00037 state=LedOF; 00038 } 00039 void LedOF(void){ 00040 pc.printf("OFF"); 00041 state=PrepThings; 00042 } 00043 void PrepThings(void){ 00044 pc.printf("preparing"); 00045 state=SendThings; 00046 }
Generated on Wed Jul 27 2022 02:39:53 by
1.7.2