1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef MBED_DIGITALIN_H
17 #define MBED_DIGITALIN_H
25 /** A digital input, used for reading the state of a pin
29 * // Flash an LED while a DigitalIn is true
33 * DigitalIn enable(p5);
34 * DigitalOut led(LED1);
49 /** Create a DigitalIn connected to the specified pin
51 * @param pin DigitalIn pin to connect to
53 DigitalIn(PinName pin) : gpio() {
54 gpio_init_in(&gpio, pin);
57 /** Create a DigitalIn connected to the specified pin
59 * @param pin DigitalIn pin to connect to
60 * @param mode the initial mode of the pin
62 DigitalIn(PinName pin, PinMode mode) : gpio() {
63 gpio_init_in_ex(&gpio, pin, mode);
65 /** Read the input, represented as 0 or 1 (int)
68 * An integer representing the state of the input pin,
69 * 0 for logical 0, 1 for logical 1
72 return gpio_read(&gpio);
75 /** Set the input pin mode
77 * @param mode PullUp, PullDown, PullNone, OpenDrain
79 void mode(PinMode pull) {
80 gpio_mode(&gpio, pull);
83 /** Return the output setting, represented as 0 or 1 (int)
86 * Non zero value if pin is connected to uc GPIO
87 * 0 if gpio object was initialized with NC
90 return gpio_is_connected(&gpio);
94 /** An operator shorthand for read()