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_PORTIN_H
ethaderu 3:78f223d34f36 17 #define MBED_PORTIN_H
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 #include "platform.h"
ethaderu 3:78f223d34f36 20
ethaderu 3:78f223d34f36 21 #if DEVICE_PORTIN
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 #include "port_api.h"
ethaderu 3:78f223d34f36 24
ethaderu 3:78f223d34f36 25 namespace mbed {
ethaderu 3:78f223d34f36 26
ethaderu 3:78f223d34f36 27 /** A multiple pin digital input
ethaderu 3:78f223d34f36 28 *
ethaderu 3:78f223d34f36 29 * Example:
ethaderu 3:78f223d34f36 30 * @code
ethaderu 3:78f223d34f36 31 * // Switch on an LED if any of mbed pins 21-26 is high
ethaderu 3:78f223d34f36 32 *
ethaderu 3:78f223d34f36 33 * #include "mbed.h"
ethaderu 3:78f223d34f36 34 *
ethaderu 3:78f223d34f36 35 * PortIn p(Port2, 0x0000003F); // p21-p26
ethaderu 3:78f223d34f36 36 * DigitalOut ind(LED4);
ethaderu 3:78f223d34f36 37 *
ethaderu 3:78f223d34f36 38 * int main() {
ethaderu 3:78f223d34f36 39 * while(1) {
ethaderu 3:78f223d34f36 40 * int pins = p.read();
ethaderu 3:78f223d34f36 41 * if(pins) {
ethaderu 3:78f223d34f36 42 * ind = 1;
ethaderu 3:78f223d34f36 43 * } else {
ethaderu 3:78f223d34f36 44 * ind = 0;
ethaderu 3:78f223d34f36 45 * }
ethaderu 3:78f223d34f36 46 * }
ethaderu 3:78f223d34f36 47 * }
ethaderu 3:78f223d34f36 48 * @endcode
ethaderu 3:78f223d34f36 49 */
ethaderu 3:78f223d34f36 50 class PortIn {
ethaderu 3:78f223d34f36 51 public:
ethaderu 3:78f223d34f36 52
ethaderu 3:78f223d34f36 53 /** Create an PortIn, connected to the specified port
ethaderu 3:78f223d34f36 54 *
ethaderu 3:78f223d34f36 55 * @param port Port to connect to (Port0-Port5)
ethaderu 3:78f223d34f36 56 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
ethaderu 3:78f223d34f36 57 */
ethaderu 3:78f223d34f36 58 PortIn(PortName port, int mask = 0xFFFFFFFF) {
ethaderu 3:78f223d34f36 59 port_init(&_port, port, mask, PIN_INPUT);
ethaderu 3:78f223d34f36 60 }
ethaderu 3:78f223d34f36 61
ethaderu 3:78f223d34f36 62 /** Read the value currently output on the port
ethaderu 3:78f223d34f36 63 *
ethaderu 3:78f223d34f36 64 * @returns
ethaderu 3:78f223d34f36 65 * An integer with each bit corresponding to associated port pin setting
ethaderu 3:78f223d34f36 66 */
ethaderu 3:78f223d34f36 67 int read() {
ethaderu 3:78f223d34f36 68 return port_read(&_port);
ethaderu 3:78f223d34f36 69 }
ethaderu 3:78f223d34f36 70
ethaderu 3:78f223d34f36 71 /** Set the input pin mode
ethaderu 3:78f223d34f36 72 *
ethaderu 3:78f223d34f36 73 * @param mode PullUp, PullDown, PullNone, OpenDrain
ethaderu 3:78f223d34f36 74 */
ethaderu 3:78f223d34f36 75 void mode(PinMode mode) {
ethaderu 3:78f223d34f36 76 port_mode(&_port, mode);
ethaderu 3:78f223d34f36 77 }
ethaderu 3:78f223d34f36 78
ethaderu 3:78f223d34f36 79 /** A shorthand for read()
ethaderu 3:78f223d34f36 80 */
ethaderu 3:78f223d34f36 81 operator int() {
ethaderu 3:78f223d34f36 82 return read();
ethaderu 3:78f223d34f36 83 }
ethaderu 3:78f223d34f36 84
ethaderu 3:78f223d34f36 85 private:
ethaderu 3:78f223d34f36 86 port_t _port;
ethaderu 3:78f223d34f36 87 };
ethaderu 3:78f223d34f36 88
ethaderu 3:78f223d34f36 89 } // namespace mbed
ethaderu 3:78f223d34f36 90
ethaderu 3:78f223d34f36 91 #endif
ethaderu 3:78f223d34f36 92
ethaderu 3:78f223d34f36 93 #endif