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.
Committer:
sarahmarshy
Date:
Tue Jun 27 11:04:14 2017 -0500
Revision:
7:5ed5244f3929
Parent:
5:65ab82bfa4a6
"Update mbed-os"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 4:3f69262115b3 1 /* mbed Example Program
mbedAustin 4:3f69262115b3 2 * Copyright (c) 2006-2014 ARM Limited
mbedAustin 4:3f69262115b3 3 *
mbedAustin 4:3f69262115b3 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 4:3f69262115b3 5 * you may not use this file except in compliance with the License.
mbedAustin 4:3f69262115b3 6 * You may obtain a copy of the License at
mbedAustin 4:3f69262115b3 7 *
mbedAustin 4:3f69262115b3 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 4:3f69262115b3 9 *
mbedAustin 4:3f69262115b3 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 4:3f69262115b3 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 4:3f69262115b3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 4:3f69262115b3 13 * See the License for the specific language governing permissions and
mbedAustin 4:3f69262115b3 14 * limitations under the License.
mbedAustin 4:3f69262115b3 15 */
mbed_official 0:0d0417932681 16 #include "mbed.h"
mbedAustin 5:65ab82bfa4a6 17
mbedAustin 5:65ab82bfa4a6 18 DigitalInOut mypin(LED1);
mbedAustin 5:65ab82bfa4a6 19
mbedAustin 5:65ab82bfa4a6 20 int main()
mbedAustin 5:65ab82bfa4a6 21 {
mbedAustin 5:65ab82bfa4a6 22 // check that mypin object is initialized and connected to a pin
mbedAustin 5:65ab82bfa4a6 23 if(mypin.is_connected()) {
mbedAustin 5:65ab82bfa4a6 24 printf("mypin is initialized and connected!\n\r");
mbedAustin 5:65ab82bfa4a6 25 }
mbedAustin 5:65ab82bfa4a6 26
mbedAustin 5:65ab82bfa4a6 27 // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain
mbedAustin 5:65ab82bfa4a6 28 mypin.mode(PullNone);
mbedAustin 5:65ab82bfa4a6 29
mbedAustin 5:65ab82bfa4a6 30 while(1) {
mbedAustin 5:65ab82bfa4a6 31 // write to pin as output
mbedAustin 5:65ab82bfa4a6 32 mypin.output();
mbedAustin 5:65ab82bfa4a6 33 mypin = !mypin; // toggle output
mbedAustin 5:65ab82bfa4a6 34 wait(0.5);
mbedAustin 5:65ab82bfa4a6 35
mbedAustin 5:65ab82bfa4a6 36 // read from pin as input
mbedAustin 5:65ab82bfa4a6 37 mypin.input();
mbedAustin 5:65ab82bfa4a6 38 printf("mypin.read() = %d \n\r",mypin.read());
mbedAustin 5:65ab82bfa4a6 39 wait(0.5);
mbedAustin 5:65ab82bfa4a6 40 }
mbed_official 0:0d0417932681 41 }