PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skrawool 0:3954a906acc2 1 /* mbed Microcontroller Library
skrawool 0:3954a906acc2 2 * Copyright (c) 2006-2013 ARM Limited
skrawool 0:3954a906acc2 3 *
skrawool 0:3954a906acc2 4 * Licensed under the Apache License, Version 2.0 (the "License");
skrawool 0:3954a906acc2 5 * you may not use this file except in compliance with the License.
skrawool 0:3954a906acc2 6 * You may obtain a copy of the License at
skrawool 0:3954a906acc2 7 *
skrawool 0:3954a906acc2 8 * http://www.apache.org/licenses/LICENSE-2.0
skrawool 0:3954a906acc2 9 *
skrawool 0:3954a906acc2 10 * Unless required by applicable law or agreed to in writing, software
skrawool 0:3954a906acc2 11 * distributed under the License is distributed on an "AS IS" BASIS,
skrawool 0:3954a906acc2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skrawool 0:3954a906acc2 13 * See the License for the specific language governing permissions and
skrawool 0:3954a906acc2 14 * limitations under the License.
skrawool 0:3954a906acc2 15 */
skrawool 0:3954a906acc2 16 #ifndef MBED_PORTIN_H
skrawool 0:3954a906acc2 17 #define MBED_PORTIN_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20
skrawool 0:3954a906acc2 21 #if DEVICE_PORTIN
skrawool 0:3954a906acc2 22
skrawool 0:3954a906acc2 23 #include "hal/port_api.h"
skrawool 0:3954a906acc2 24 #include "platform/critical.h"
skrawool 0:3954a906acc2 25
skrawool 0:3954a906acc2 26 namespace mbed {
skrawool 0:3954a906acc2 27 /** \addtogroup drivers */
skrawool 0:3954a906acc2 28 /** @{*/
skrawool 0:3954a906acc2 29
skrawool 0:3954a906acc2 30 /** A multiple pin digital input
skrawool 0:3954a906acc2 31 *
skrawool 0:3954a906acc2 32 * @Note Synchronization level: Interrupt safe
skrawool 0:3954a906acc2 33 *
skrawool 0:3954a906acc2 34 * Example:
skrawool 0:3954a906acc2 35 * @code
skrawool 0:3954a906acc2 36 * // Switch on an LED if any of mbed pins 21-26 is high
skrawool 0:3954a906acc2 37 *
skrawool 0:3954a906acc2 38 * #include "mbed.h"
skrawool 0:3954a906acc2 39 *
skrawool 0:3954a906acc2 40 * PortIn p(Port2, 0x0000003F); // p21-p26
skrawool 0:3954a906acc2 41 * DigitalOut ind(LED4);
skrawool 0:3954a906acc2 42 *
skrawool 0:3954a906acc2 43 * int main() {
skrawool 0:3954a906acc2 44 * while(1) {
skrawool 0:3954a906acc2 45 * int pins = p.read();
skrawool 0:3954a906acc2 46 * if(pins) {
skrawool 0:3954a906acc2 47 * ind = 1;
skrawool 0:3954a906acc2 48 * } else {
skrawool 0:3954a906acc2 49 * ind = 0;
skrawool 0:3954a906acc2 50 * }
skrawool 0:3954a906acc2 51 * }
skrawool 0:3954a906acc2 52 * }
skrawool 0:3954a906acc2 53 * @endcode
skrawool 0:3954a906acc2 54 */
skrawool 0:3954a906acc2 55 class PortIn {
skrawool 0:3954a906acc2 56 public:
skrawool 0:3954a906acc2 57
skrawool 0:3954a906acc2 58 /** Create an PortIn, connected to the specified port
skrawool 0:3954a906acc2 59 *
skrawool 0:3954a906acc2 60 * @param port Port to connect to (Port0-Port5)
skrawool 0:3954a906acc2 61 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
skrawool 0:3954a906acc2 62 */
skrawool 0:3954a906acc2 63 PortIn(PortName port, int mask = 0xFFFFFFFF) {
skrawool 0:3954a906acc2 64 core_util_critical_section_enter();
skrawool 0:3954a906acc2 65 port_init(&_port, port, mask, PIN_INPUT);
skrawool 0:3954a906acc2 66 core_util_critical_section_exit();
skrawool 0:3954a906acc2 67 }
skrawool 0:3954a906acc2 68
skrawool 0:3954a906acc2 69 /** Read the value currently output on the port
skrawool 0:3954a906acc2 70 *
skrawool 0:3954a906acc2 71 * @returns
skrawool 0:3954a906acc2 72 * An integer with each bit corresponding to associated port pin setting
skrawool 0:3954a906acc2 73 */
skrawool 0:3954a906acc2 74 int read() {
skrawool 0:3954a906acc2 75 return port_read(&_port);
skrawool 0:3954a906acc2 76 }
skrawool 0:3954a906acc2 77
skrawool 0:3954a906acc2 78 /** Set the input pin mode
skrawool 0:3954a906acc2 79 *
skrawool 0:3954a906acc2 80 * @param mode PullUp, PullDown, PullNone, OpenDrain
skrawool 0:3954a906acc2 81 */
skrawool 0:3954a906acc2 82 void mode(PinMode mode) {
skrawool 0:3954a906acc2 83 core_util_critical_section_enter();
skrawool 0:3954a906acc2 84 port_mode(&_port, mode);
skrawool 0:3954a906acc2 85 core_util_critical_section_exit();
skrawool 0:3954a906acc2 86 }
skrawool 0:3954a906acc2 87
skrawool 0:3954a906acc2 88 /** A shorthand for read()
skrawool 0:3954a906acc2 89 */
skrawool 0:3954a906acc2 90 operator int() {
skrawool 0:3954a906acc2 91 return read();
skrawool 0:3954a906acc2 92 }
skrawool 0:3954a906acc2 93
skrawool 0:3954a906acc2 94 private:
skrawool 0:3954a906acc2 95 port_t _port;
skrawool 0:3954a906acc2 96 };
skrawool 0:3954a906acc2 97
skrawool 0:3954a906acc2 98 } // namespace mbed
skrawool 0:3954a906acc2 99
skrawool 0:3954a906acc2 100 #endif
skrawool 0:3954a906acc2 101
skrawool 0:3954a906acc2 102 #endif
skrawool 0:3954a906acc2 103
skrawool 0:3954a906acc2 104 /** @}*/