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_DIGITALOUT_H
17 #define MBED_DIGITALOUT_H
24 /** A digital output, used for setting the state of a pin
31 * DigitalOut led(LED1);
44 /** Create a DigitalOut connected to the specified pin
46 * @param pin DigitalOut pin to connect to
48 DigitalOut(PinName pin) : gpio() {
49 gpio_init_out(&gpio, pin);
52 /** Create a DigitalOut connected to the specified pin
54 * @param pin DigitalOut pin to connect to
55 * @param value the initial pin value
57 DigitalOut(PinName pin, int value) : gpio() {
58 gpio_init_out_ex(&gpio, pin, value);
61 /** Set the output, specified as 0 or 1 (int)
63 * @param value An integer specifying the pin output value,
64 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
66 void write(int value) {
67 gpio_write(&gpio, value);
70 /** Return the output setting, represented as 0 or 1 (int)
73 * an integer representing the output setting of the pin,
74 * 0 for logical 0, 1 for logical 1
77 return gpio_read(&gpio);
80 /** Return the output setting, represented as 0 or 1 (int)
83 * Non zero value if pin is connected to uc GPIO
84 * 0 if gpio object was initialized with NC
87 return gpio_is_connected(&gpio);
91 /** A shorthand for write()
93 DigitalOut& operator= (int value) {
98 DigitalOut& operator= (DigitalOut& rhs) {
103 /** A shorthand for read()