This program shows, how a serial interrupt can be handled. Here a state machine is set up where the states can be changed from \'offline\' to \'online\' and backwards over UART

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
goeckeritz
Date:
Wed Apr 20 10:00:26 2011 +0000
Commit message:
initial upload

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r edfedf459fb2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 20 10:00:26 2011 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut led(LED1);
+
+DigitalOut led2(LED2, "led2");
+DigitalOut led3(LED3, "led3");
+DigitalOut led4(LED4, "led4");
+bool lineState = 0;
+
+char string[BUFSIZ];
+
+void allOn()
+{
+    pc.scanf("%s", &string);
+ 
+    //if(pc.readable()){
+    //pc.scanf("%s", &string);
+
+    if(!strcmp(string, "#online"))
+    {
+        lineState = 1;
+        pc.printf("This thing is online\n");
+    }
+    if(!strcmp(string, "#offline"))
+    {
+        lineState = 0;
+        pc.printf("This thing is offline\n"); 
+    }
+    pc.printf("%s\n", string);      
+
+    led2 =! led2;
+    led3 =! led3;
+    led4 =! led4; 
+}
+
+
+
+int main() {
+    pc.printf("Serial interrupt handler state machine\nstate changeble by typing '#online' or '#offline'\n\n");
+    pc.attach(&allOn);
+    
+    while(1) {
+        wait(1);
+        pc.printf("lineState: %i\n",lineState); 
+    }
+}
diff -r 000000000000 -r edfedf459fb2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 20 10:00:26 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912