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_PORTINOUT_H
skrawool 0:3954a906acc2 17 #define MBED_PORTINOUT_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20
skrawool 0:3954a906acc2 21 #if DEVICE_PORTINOUT
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 in/out used to set/read multiple bi-directional pins
skrawool 0:3954a906acc2 31 *
skrawool 0:3954a906acc2 32 * @Note Synchronization level: Interrupt safe
skrawool 0:3954a906acc2 33 */
skrawool 0:3954a906acc2 34 class PortInOut {
skrawool 0:3954a906acc2 35 public:
skrawool 0:3954a906acc2 36
skrawool 0:3954a906acc2 37 /** Create an PortInOut, connected to the specified port
skrawool 0:3954a906acc2 38 *
skrawool 0:3954a906acc2 39 * @param port Port to connect to (Port0-Port5)
skrawool 0:3954a906acc2 40 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
skrawool 0:3954a906acc2 41 */
skrawool 0:3954a906acc2 42 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
skrawool 0:3954a906acc2 43 core_util_critical_section_enter();
skrawool 0:3954a906acc2 44 port_init(&_port, port, mask, PIN_INPUT);
skrawool 0:3954a906acc2 45 core_util_critical_section_exit();
skrawool 0:3954a906acc2 46 }
skrawool 0:3954a906acc2 47
skrawool 0:3954a906acc2 48 /** Write the value to the output port
skrawool 0:3954a906acc2 49 *
skrawool 0:3954a906acc2 50 * @param value An integer specifying a bit to write for every corresponding port pin
skrawool 0:3954a906acc2 51 */
skrawool 0:3954a906acc2 52 void write(int value) {
skrawool 0:3954a906acc2 53 port_write(&_port, value);
skrawool 0:3954a906acc2 54 }
skrawool 0:3954a906acc2 55
skrawool 0:3954a906acc2 56 /** Read the value currently output on the port
skrawool 0:3954a906acc2 57 *
skrawool 0:3954a906acc2 58 * @returns
skrawool 0:3954a906acc2 59 * An integer with each bit corresponding to associated port pin setting
skrawool 0:3954a906acc2 60 */
skrawool 0:3954a906acc2 61 int read() {
skrawool 0:3954a906acc2 62 return port_read(&_port);
skrawool 0:3954a906acc2 63 }
skrawool 0:3954a906acc2 64
skrawool 0:3954a906acc2 65 /** Set as an output
skrawool 0:3954a906acc2 66 */
skrawool 0:3954a906acc2 67 void output() {
skrawool 0:3954a906acc2 68 core_util_critical_section_enter();
skrawool 0:3954a906acc2 69 port_dir(&_port, PIN_OUTPUT);
skrawool 0:3954a906acc2 70 core_util_critical_section_exit();
skrawool 0:3954a906acc2 71 }
skrawool 0:3954a906acc2 72
skrawool 0:3954a906acc2 73 /** Set as an input
skrawool 0:3954a906acc2 74 */
skrawool 0:3954a906acc2 75 void input() {
skrawool 0:3954a906acc2 76 core_util_critical_section_enter();
skrawool 0:3954a906acc2 77 port_dir(&_port, PIN_INPUT);
skrawool 0:3954a906acc2 78 core_util_critical_section_exit();
skrawool 0:3954a906acc2 79 }
skrawool 0:3954a906acc2 80
skrawool 0:3954a906acc2 81 /** Set the input pin mode
skrawool 0:3954a906acc2 82 *
skrawool 0:3954a906acc2 83 * @param mode PullUp, PullDown, PullNone, OpenDrain
skrawool 0:3954a906acc2 84 */
skrawool 0:3954a906acc2 85 void mode(PinMode mode) {
skrawool 0:3954a906acc2 86 core_util_critical_section_enter();
skrawool 0:3954a906acc2 87 port_mode(&_port, mode);
skrawool 0:3954a906acc2 88 core_util_critical_section_exit();
skrawool 0:3954a906acc2 89 }
skrawool 0:3954a906acc2 90
skrawool 0:3954a906acc2 91 /** A shorthand for write()
skrawool 0:3954a906acc2 92 */
skrawool 0:3954a906acc2 93 PortInOut& operator= (int value) {
skrawool 0:3954a906acc2 94 write(value);
skrawool 0:3954a906acc2 95 return *this;
skrawool 0:3954a906acc2 96 }
skrawool 0:3954a906acc2 97
skrawool 0:3954a906acc2 98 PortInOut& operator= (PortInOut& rhs) {
skrawool 0:3954a906acc2 99 write(rhs.read());
skrawool 0:3954a906acc2 100 return *this;
skrawool 0:3954a906acc2 101 }
skrawool 0:3954a906acc2 102
skrawool 0:3954a906acc2 103 /** A shorthand for read()
skrawool 0:3954a906acc2 104 */
skrawool 0:3954a906acc2 105 operator int() {
skrawool 0:3954a906acc2 106 return read();
skrawool 0:3954a906acc2 107 }
skrawool 0:3954a906acc2 108
skrawool 0:3954a906acc2 109 private:
skrawool 0:3954a906acc2 110 port_t _port;
skrawool 0:3954a906acc2 111 };
skrawool 0:3954a906acc2 112
skrawool 0:3954a906acc2 113 } // namespace mbed
skrawool 0:3954a906acc2 114
skrawool 0:3954a906acc2 115 #endif
skrawool 0:3954a906acc2 116
skrawool 0:3954a906acc2 117 #endif
skrawool 0:3954a906acc2 118
skrawool 0:3954a906acc2 119 /** @}*/