LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 08:51:33 2018 +0000
Revision:
0:871ab6846b18
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
H_Tsunemoto 0:871ab6846b18 1 /* mbed Microcontroller Library
H_Tsunemoto 0:871ab6846b18 2 * Copyright (c) 2006-2013 ARM Limited
H_Tsunemoto 0:871ab6846b18 3 *
H_Tsunemoto 0:871ab6846b18 4 * Licensed under the Apache License, Version 2.0 (the "License");
H_Tsunemoto 0:871ab6846b18 5 * you may not use this file except in compliance with the License.
H_Tsunemoto 0:871ab6846b18 6 * You may obtain a copy of the License at
H_Tsunemoto 0:871ab6846b18 7 *
H_Tsunemoto 0:871ab6846b18 8 * http://www.apache.org/licenses/LICENSE-2.0
H_Tsunemoto 0:871ab6846b18 9 *
H_Tsunemoto 0:871ab6846b18 10 * Unless required by applicable law or agreed to in writing, software
H_Tsunemoto 0:871ab6846b18 11 * distributed under the License is distributed on an "AS IS" BASIS,
H_Tsunemoto 0:871ab6846b18 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
H_Tsunemoto 0:871ab6846b18 13 * See the License for the specific language governing permissions and
H_Tsunemoto 0:871ab6846b18 14 * limitations under the License.
H_Tsunemoto 0:871ab6846b18 15 */
H_Tsunemoto 0:871ab6846b18 16 #ifndef MBED_DIGITALIN_H
H_Tsunemoto 0:871ab6846b18 17 #define MBED_DIGITALIN_H
H_Tsunemoto 0:871ab6846b18 18
H_Tsunemoto 0:871ab6846b18 19 #include "platform.h"
H_Tsunemoto 0:871ab6846b18 20
H_Tsunemoto 0:871ab6846b18 21 #include "gpio_api.h"
H_Tsunemoto 0:871ab6846b18 22
H_Tsunemoto 0:871ab6846b18 23 namespace mbed {
H_Tsunemoto 0:871ab6846b18 24
H_Tsunemoto 0:871ab6846b18 25 /** A digital input, used for reading the state of a pin
H_Tsunemoto 0:871ab6846b18 26 *
H_Tsunemoto 0:871ab6846b18 27 * Example:
H_Tsunemoto 0:871ab6846b18 28 * @code
H_Tsunemoto 0:871ab6846b18 29 * // Flash an LED while a DigitalIn is true
H_Tsunemoto 0:871ab6846b18 30 *
H_Tsunemoto 0:871ab6846b18 31 * #include "mbed.h"
H_Tsunemoto 0:871ab6846b18 32 *
H_Tsunemoto 0:871ab6846b18 33 * DigitalIn enable(p5);
H_Tsunemoto 0:871ab6846b18 34 * DigitalOut led(LED1);
H_Tsunemoto 0:871ab6846b18 35 *
H_Tsunemoto 0:871ab6846b18 36 * int main() {
H_Tsunemoto 0:871ab6846b18 37 * while(1) {
H_Tsunemoto 0:871ab6846b18 38 * if(enable) {
H_Tsunemoto 0:871ab6846b18 39 * led = !led;
H_Tsunemoto 0:871ab6846b18 40 * }
H_Tsunemoto 0:871ab6846b18 41 * wait(0.25);
H_Tsunemoto 0:871ab6846b18 42 * }
H_Tsunemoto 0:871ab6846b18 43 * }
H_Tsunemoto 0:871ab6846b18 44 * @endcode
H_Tsunemoto 0:871ab6846b18 45 */
H_Tsunemoto 0:871ab6846b18 46 class DigitalIn {
H_Tsunemoto 0:871ab6846b18 47
H_Tsunemoto 0:871ab6846b18 48 public:
H_Tsunemoto 0:871ab6846b18 49 /** Create a DigitalIn connected to the specified pin
H_Tsunemoto 0:871ab6846b18 50 *
H_Tsunemoto 0:871ab6846b18 51 * @param pin DigitalIn pin to connect to
H_Tsunemoto 0:871ab6846b18 52 */
H_Tsunemoto 0:871ab6846b18 53 DigitalIn(PinName pin) : gpio() {
H_Tsunemoto 0:871ab6846b18 54 gpio_init_in(&gpio, pin);
H_Tsunemoto 0:871ab6846b18 55 }
H_Tsunemoto 0:871ab6846b18 56
H_Tsunemoto 0:871ab6846b18 57 /** Create a DigitalIn connected to the specified pin
H_Tsunemoto 0:871ab6846b18 58 *
H_Tsunemoto 0:871ab6846b18 59 * @param pin DigitalIn pin to connect to
H_Tsunemoto 0:871ab6846b18 60 * @param mode the initial mode of the pin
H_Tsunemoto 0:871ab6846b18 61 */
H_Tsunemoto 0:871ab6846b18 62 DigitalIn(PinName pin, PinMode mode) : gpio() {
H_Tsunemoto 0:871ab6846b18 63 gpio_init_in_ex(&gpio, pin, mode);
H_Tsunemoto 0:871ab6846b18 64 }
H_Tsunemoto 0:871ab6846b18 65 /** Read the input, represented as 0 or 1 (int)
H_Tsunemoto 0:871ab6846b18 66 *
H_Tsunemoto 0:871ab6846b18 67 * @returns
H_Tsunemoto 0:871ab6846b18 68 * An integer representing the state of the input pin,
H_Tsunemoto 0:871ab6846b18 69 * 0 for logical 0, 1 for logical 1
H_Tsunemoto 0:871ab6846b18 70 */
H_Tsunemoto 0:871ab6846b18 71 int read() {
H_Tsunemoto 0:871ab6846b18 72 return gpio_read(&gpio);
H_Tsunemoto 0:871ab6846b18 73 }
H_Tsunemoto 0:871ab6846b18 74
H_Tsunemoto 0:871ab6846b18 75 /** Set the input pin mode
H_Tsunemoto 0:871ab6846b18 76 *
H_Tsunemoto 0:871ab6846b18 77 * @param mode PullUp, PullDown, PullNone, OpenDrain
H_Tsunemoto 0:871ab6846b18 78 */
H_Tsunemoto 0:871ab6846b18 79 void mode(PinMode pull) {
H_Tsunemoto 0:871ab6846b18 80 gpio_mode(&gpio, pull);
H_Tsunemoto 0:871ab6846b18 81 }
H_Tsunemoto 0:871ab6846b18 82
H_Tsunemoto 0:871ab6846b18 83 #ifdef MBED_OPERATORS
H_Tsunemoto 0:871ab6846b18 84 /** An operator shorthand for read()
H_Tsunemoto 0:871ab6846b18 85 */
H_Tsunemoto 0:871ab6846b18 86 operator int() {
H_Tsunemoto 0:871ab6846b18 87 return read();
H_Tsunemoto 0:871ab6846b18 88 }
H_Tsunemoto 0:871ab6846b18 89 #endif
H_Tsunemoto 0:871ab6846b18 90
H_Tsunemoto 0:871ab6846b18 91 protected:
H_Tsunemoto 0:871ab6846b18 92 gpio_t gpio;
H_Tsunemoto 0:871ab6846b18 93 };
H_Tsunemoto 0:871ab6846b18 94
H_Tsunemoto 0:871ab6846b18 95 } // namespace mbed
H_Tsunemoto 0:871ab6846b18 96
H_Tsunemoto 0:871ab6846b18 97 #endif