reading only one interrupt when it changes its value

Dependencies:   Hotboards_switches mbed

Files at this revision

API Documentation at this revision

Comitter:
RomanValenciaP
Date:
Wed Mar 02 20:34:27 2016 +0000
Child:
1:af16896c2662
Commit message:
first release - recquires approval

Changed in this revision

Hotboards_switches.lib Show annotated file Show diff for this revision Revisions of this file
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/Hotboards_switches.lib	Wed Mar 02 20:34:27 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Hotboards/code/Hotboards_switches/#dfb1302f847d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 02 20:34:27 2016 +0000
@@ -0,0 +1,41 @@
+
+/*
+ * Reads an input on pin PB_4, only when its value has been changed
+ */
+ 
+#include "mbed.h"
+#include "Hotboards_switches.h"
+
+// Creates a single sw object, this interrupt will give us a LOW(0) value when close
+// because our dip switch works with pull-ups
+Hotboards_switches sw( PB_4 );
+// If your dip switch will gave you a HIGH(1) value when close, then we need to create
+// the sw object with an extra parameter: Hotboards_switches sw( PB_4 , 1 );
+// In any case the function will return a HIGH(1) value any time the sw is closed
+
+// For this example we will use the USB serial port, here we initialize it
+Serial pc(USBTX,USBRX);
+
+int main()
+{
+    while(1)
+    {
+        //Asks when the interrupt changes its value
+        if( sw.hasItChange( ) )
+        {
+            // When the interrupt is close (or ON) the function will return a true value
+            // it doesn´t matter if our input is configured with pull-ups(LOW) or
+            // pull-downs(HIGH)
+            if( sw.read( ) )
+            {
+                pc.printf( "sw = close (on)\n\r" );
+            }
+            else
+            {
+                pc.printf( "sw = open (off)\n\r" );
+            }
+            // Wait 250 ms, just to not query so often
+            wait_ms( 250 );
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Mar 02 20:34:27 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file