Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

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_DIGITALINOUT_H
ethaderu 3:78f223d34f36 17 #define MBED_DIGITALINOUT_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/output, used for setting or reading a bi-directional pin
ethaderu 3:78f223d34f36 26 */
ethaderu 3:78f223d34f36 27 class DigitalInOut {
ethaderu 3:78f223d34f36 28
ethaderu 3:78f223d34f36 29 public:
ethaderu 3:78f223d34f36 30 /** Create a DigitalInOut connected to the specified pin
ethaderu 3:78f223d34f36 31 *
ethaderu 3:78f223d34f36 32 * @param pin DigitalInOut pin to connect to
ethaderu 3:78f223d34f36 33 */
ethaderu 3:78f223d34f36 34 DigitalInOut(PinName pin) : gpio() {
ethaderu 3:78f223d34f36 35 gpio_init_in(&gpio, pin);
ethaderu 3:78f223d34f36 36 }
ethaderu 3:78f223d34f36 37
ethaderu 3:78f223d34f36 38 /** Create a DigitalInOut connected to the specified pin
ethaderu 3:78f223d34f36 39 *
ethaderu 3:78f223d34f36 40 * @param pin DigitalInOut pin to connect to
ethaderu 3:78f223d34f36 41 * @param direction the initial direction of the pin
ethaderu 3:78f223d34f36 42 * @param mode the initial mode of the pin
ethaderu 3:78f223d34f36 43 * @param value the initial value of the pin if is an output
ethaderu 3:78f223d34f36 44 */
ethaderu 3:78f223d34f36 45 DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
ethaderu 3:78f223d34f36 46 gpio_init_inout(&gpio, pin, direction, mode, value);
ethaderu 3:78f223d34f36 47 }
ethaderu 3:78f223d34f36 48
ethaderu 3:78f223d34f36 49 /** Set the output, specified as 0 or 1 (int)
ethaderu 3:78f223d34f36 50 *
ethaderu 3:78f223d34f36 51 * @param value An integer specifying the pin output value,
ethaderu 3:78f223d34f36 52 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
ethaderu 3:78f223d34f36 53 */
ethaderu 3:78f223d34f36 54 void write(int value) {
ethaderu 3:78f223d34f36 55 gpio_write(&gpio, value);
ethaderu 3:78f223d34f36 56 }
ethaderu 3:78f223d34f36 57
ethaderu 3:78f223d34f36 58 /** Return the output setting, represented as 0 or 1 (int)
ethaderu 3:78f223d34f36 59 *
ethaderu 3:78f223d34f36 60 * @returns
ethaderu 3:78f223d34f36 61 * an integer representing the output setting of the pin if it is an output,
ethaderu 3:78f223d34f36 62 * or read the input if set as an input
ethaderu 3:78f223d34f36 63 */
ethaderu 3:78f223d34f36 64 int read() {
ethaderu 3:78f223d34f36 65 return gpio_read(&gpio);
ethaderu 3:78f223d34f36 66 }
ethaderu 3:78f223d34f36 67
ethaderu 3:78f223d34f36 68 /** Set as an output
ethaderu 3:78f223d34f36 69 */
ethaderu 3:78f223d34f36 70 void output() {
ethaderu 3:78f223d34f36 71 gpio_dir(&gpio, PIN_OUTPUT);
ethaderu 3:78f223d34f36 72 }
ethaderu 3:78f223d34f36 73
ethaderu 3:78f223d34f36 74 /** Set as an input
ethaderu 3:78f223d34f36 75 */
ethaderu 3:78f223d34f36 76 void input() {
ethaderu 3:78f223d34f36 77 gpio_dir(&gpio, PIN_INPUT);
ethaderu 3:78f223d34f36 78 }
ethaderu 3:78f223d34f36 79
ethaderu 3:78f223d34f36 80 /** Set the input pin mode
ethaderu 3:78f223d34f36 81 *
ethaderu 3:78f223d34f36 82 * @param mode PullUp, PullDown, PullNone, OpenDrain
ethaderu 3:78f223d34f36 83 */
ethaderu 3:78f223d34f36 84 void mode(PinMode pull) {
ethaderu 3:78f223d34f36 85 gpio_mode(&gpio, pull);
ethaderu 3:78f223d34f36 86 }
ethaderu 3:78f223d34f36 87
ethaderu 3:78f223d34f36 88 /** Return the output setting, represented as 0 or 1 (int)
ethaderu 3:78f223d34f36 89 *
ethaderu 3:78f223d34f36 90 * @returns
ethaderu 3:78f223d34f36 91 * Non zero value if pin is connected to uc GPIO
ethaderu 3:78f223d34f36 92 * 0 if gpio object was initialized with NC
ethaderu 3:78f223d34f36 93 */
ethaderu 3:78f223d34f36 94 int is_connected() {
ethaderu 3:78f223d34f36 95 return gpio_is_connected(&gpio);
ethaderu 3:78f223d34f36 96 }
ethaderu 3:78f223d34f36 97
ethaderu 3:78f223d34f36 98 #ifdef MBED_OPERATORS
ethaderu 3:78f223d34f36 99 /** A shorthand for write()
ethaderu 3:78f223d34f36 100 */
ethaderu 3:78f223d34f36 101 DigitalInOut& operator= (int value) {
ethaderu 3:78f223d34f36 102 write(value);
ethaderu 3:78f223d34f36 103 return *this;
ethaderu 3:78f223d34f36 104 }
ethaderu 3:78f223d34f36 105
ethaderu 3:78f223d34f36 106 DigitalInOut& operator= (DigitalInOut& rhs) {
ethaderu 3:78f223d34f36 107 write(rhs.read());
ethaderu 3:78f223d34f36 108 return *this;
ethaderu 3:78f223d34f36 109 }
ethaderu 3:78f223d34f36 110
ethaderu 3:78f223d34f36 111 /** A shorthand for read()
ethaderu 3:78f223d34f36 112 */
ethaderu 3:78f223d34f36 113 operator int() {
ethaderu 3:78f223d34f36 114 return read();
ethaderu 3:78f223d34f36 115 }
ethaderu 3:78f223d34f36 116 #endif
ethaderu 3:78f223d34f36 117
ethaderu 3:78f223d34f36 118 protected:
ethaderu 3:78f223d34f36 119 gpio_t gpio;
ethaderu 3:78f223d34f36 120 };
ethaderu 3:78f223d34f36 121
ethaderu 3:78f223d34f36 122 } // namespace mbed
ethaderu 3:78f223d34f36 123
ethaderu 3:78f223d34f36 124 #endif