This sketch shown how to read a single switch with pull up resistor

Dependencies:   mbed

Revision:
0:fb95cef55dd9
diff -r 000000000000 -r fb95cef55dd9 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 18 18:12:03 2016 +0000
@@ -0,0 +1,26 @@
+/*
+ * Hotboards_Switches_Reading_Single_Switch
+ * This sketch demonstrates how to read a single switch, 
+ * example created by Pedro from (http://www.hotboards.org)
+ */
+
+#include "mbed.h" 
+
+DigitalIn SW1(PC_8);   // Switch connected on PC_8
+DigitalOut led(PB_14); // led connected on PB_14
+
+/*switches in this example have a pull up resistors*/
+int main() 
+{ 
+  while(1)          
+  { 
+   if(SW1 == 1)     /* if switch is in OFF position*/ 
+   { 
+     led = 0;       /* led OFF*/ 
+   } 
+   else             /* switch in ON position*/ 
+   { 
+     led = 1;       /* Led ON*/ 
+   } 
+  } 
+}