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.
Diff: main.cpp
- Revision:
- 0:7cd6baddb768
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu May 28 18:37:18 2015 +0000
@@ -0,0 +1,64 @@
+/*****************************************************************/
+/* How to use State Machines in C */
+/* Switch|Case */
+/*****************************************************************/
+
+// Librarys:
+#include "mbed.h"
+
+// Configuration:
+DigitalOut led(LED1);
+Serial pc(USBTX,USBRX);
+
+//Functions
+
+
+int main(){
+/************STATES**************/
+ enum states{
+ LED_OF_1S,
+ LED_ON_2S,
+ LED_OF_3S,
+ LED_ON_4S
+ };
+ enum states state = LED_OF_1S;
+while(1){
+ switch(state){
+ case LED_OF_1S:
+
+ //Led off for 1 second:
+ led=0;
+ pc.printf("LED_OF");
+ wait(1);
+ state = LED_ON_2S;
+
+ break;
+ case LED_ON_2S:
+
+ //Led on for 2 seconds:
+ led=1;
+ pc.printf("LED_ON");
+ wait(2);
+ state = LED_OF_3S;
+
+ break;
+ case LED_OF_3S:
+
+ //Led off for 3 seconds:
+ led=0;
+ pc.printf("LED_OF");
+ wait(3);
+ state = LED_ON_4S;
+ break;
+ case LED_ON_4S:
+
+ //Led on for 4 seconds:
+ led=1;
+ pc.printf("LED_ON");
+ wait(4);
+ state = LED_OF_1S;
+ break;
+ }
+ }
+}
+