MultiTech / Mbed 2 deprecated Dragonfly_DigitalIn_BusIn_Example

Dependencies:   mbed

Revision:
0:c7d463ff3deb
Child:
1:5770646ab65b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 01 20:21:44 2015 +0000
@@ -0,0 +1,37 @@
+/** Dragonfly DigitalIn, BusIn, and InterruptIn Example Program
+ *
+ * This program demonstrates how to read digital inputs using the
+ * MultiTech Dragonfly and MultiTech UDK2 hardware. The only
+ * additional hardware required is jumper wires.
+ *
+ * Pins are active low, so 0V = 0 and 5V/3.3V = 1.
+ *
+ * This program prints the new value of the BusIn each time it changes
+ * and the new value of the DigitalIn each time it changes.
+ */
+ 
+#include "mbed.h"
+ 
+int main() {
+    // read digital pins D9 and D10 as a 2 pin bus
+    // the first pin is the LSB of the bus, the last is the MSB
+    BusIn bus(D9, D10);
+    // read digital pin D12
+    DigitalIn din(D12);
+    
+    int old_bus = -1;
+    int old_din = -1;
+    
+    while (true) {
+        if (bus != old_bus) {
+            old_bus = bus;
+            printf("bus = %d\r\n", old_bus);
+        }
+        if (din != old_din) {
+            old_din = din;
+            printf("din = %d\r\n", old_din);
+        }
+        
+        wait_ms(100);
+    }
+}
\ No newline at end of file