LED is switched on and off by typing 1,2,3 and 4

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Parkz
Date:
Sat Jul 13 09:14:11 2013 +0000
Commit message:
The scanf function here doesnt seem to be working. Please help me!

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 13 09:14:11 2013 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include<stdio.h>
+Serial pc(USBTX,USBRX);
+DigitalOut leds[]={(LED1),(LED2),(LED3),(LED4)};
+void ledon(int no)
+{
+    if(leds[no]==0)
+        {
+            leds[no]=1;
+        }
+    else
+        {
+            leds[no]=0;
+        }
+}
+
+int main()
+    {
+        int buffer=0;
+        a:
+             pc.printf("\nType numbers 1,2,3,4 to switch respective leds on and off\n");
+             pc.scanf("%d",&buffer);
+             pc.printf("Its %d\n",buffer);
+             switch(buffer)
+                {
+                    case 1:ledon(buffer-1);
+                    break;
+                    case 2:ledon(buffer-1);
+                    break;
+                    case 3:ledon(buffer-1);
+                    break;
+                    case 4:ledon(buffer-1);
+                }
+        goto a;
+    }
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jul 13 09:14:11 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file