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

Revision:
0:edfedf459fb2
--- /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); 
+    }
+}