Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DigitalIn.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_DIGITALIN_H 00017 #define MBED_DIGITALIN_H 00018 00019 #include "platform.h" 00020 00021 #include "gpio_api.h" 00022 00023 namespace mbed { 00024 00025 /** A digital input, used for reading the state of a pin 00026 * 00027 * Example: 00028 * @code 00029 * // Flash an LED while a DigitalIn is true 00030 * 00031 * #include "mbed.h" 00032 * 00033 * DigitalIn enable(p5); 00034 * DigitalOut led(LED1); 00035 * 00036 * int main() { 00037 * while(1) { 00038 * if(enable) { 00039 * led = !led; 00040 * } 00041 * wait(0.25); 00042 * } 00043 * } 00044 * @endcode 00045 */ 00046 class DigitalIn { 00047 00048 public: 00049 /** Create a DigitalIn connected to the specified pin 00050 * 00051 * @param pin DigitalIn pin to connect to 00052 * @param name (optional) A string to identify the object 00053 */ 00054 DigitalIn(PinName pin) { 00055 gpio_init(&gpio, pin, PIN_INPUT); 00056 } 00057 00058 /** Read the input, represented as 0 or 1 (int) 00059 * 00060 * @returns 00061 * An integer representing the state of the input pin, 00062 * 0 for logical 0, 1 for logical 1 00063 */ 00064 int read() { 00065 return gpio_read(&gpio); 00066 } 00067 00068 /** Set the input pin mode 00069 * 00070 * @param mode PullUp, PullDown, PullNone, OpenDrain 00071 */ 00072 void mode(PinMode pull) { 00073 gpio_mode(&gpio, pull); 00074 } 00075 00076 #ifdef MBED_OPERATORS 00077 /** An operator shorthand for read() 00078 */ 00079 operator int() { 00080 return read(); 00081 } 00082 #endif 00083 00084 protected: 00085 gpio_t gpio; 00086 }; 00087 00088 } // namespace mbed 00089 00090 #endif
Generated on Tue Jul 12 2022 12:14:19 by
