Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

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