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

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Hotboards
Date:
Fri Mar 18 18:12:03 2016 +0000
Commit message:
first release

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	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*/ 
+   } 
+  } 
+} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 18 18:12:03 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5
\ No newline at end of file