DigitalInOut Hello World

Fork of DigitalInOut_HelloWorld_Mbed by Mbed

Use

The DigitalInOut API can be used to both read and write a digital pin. Use the output() and input() function calls to switch modes and then use just like you would DigitalIn or DigitalOut.

API

API reference.

Import librarymbed

No documentation found.
Revision:
5:65ab82bfa4a6
Parent:
4:3f69262115b3
--- a/main.cpp	Fri Mar 27 20:13:44 2015 +0000
+++ b/main.cpp	Fri Mar 27 22:05:54 2015 +0000
@@ -14,14 +14,28 @@
  * limitations under the License.
  */
 #include "mbed.h"
- 
-DigitalInOut pin(p5);
- 
-int main() {
-    pin.output();
-    pin = 0;     // write pin value
-    wait_us(500);
-    pin.input();
-    // can read pin value here
-    wait_us(500);
+
+DigitalInOut mypin(LED1);
+
+int main()
+{
+    // check that mypin object is initialized and connected to a pin
+    if(mypin.is_connected()) {
+        printf("mypin is initialized and connected!\n\r");
+    }
+
+    // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain
+    mypin.mode(PullNone);
+
+    while(1) {
+        // write to pin as output
+        mypin.output();
+        mypin = !mypin; // toggle output
+        wait(0.5);
+
+        // read from pin as input
+        mypin.input();
+        printf("mypin.read() = %d \n\r",mypin.read());
+        wait(0.5);
+    }
 }
\ No newline at end of file