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_PORTOUT_H
skrawool 0:3954a906acc2 17 #define MBED_PORTOUT_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20
skrawool 0:3954a906acc2 21 #if DEVICE_PORTOUT
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 /** A multiple pin digital out
skrawool 0:3954a906acc2 30 *
skrawool 0:3954a906acc2 31 * @Note Synchronization level: Interrupt safe
skrawool 0:3954a906acc2 32 *
skrawool 0:3954a906acc2 33 * Example:
skrawool 0:3954a906acc2 34 * @code
skrawool 0:3954a906acc2 35 * // Toggle all four LEDs
skrawool 0:3954a906acc2 36 *
skrawool 0:3954a906acc2 37 * #include "mbed.h"
skrawool 0:3954a906acc2 38 *
skrawool 0:3954a906acc2 39 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
skrawool 0:3954a906acc2 40 * #define LED_MASK 0x00B40000
skrawool 0:3954a906acc2 41 *
skrawool 0:3954a906acc2 42 * PortOut ledport(Port1, LED_MASK);
skrawool 0:3954a906acc2 43 *
skrawool 0:3954a906acc2 44 * int main() {
skrawool 0:3954a906acc2 45 * while(1) {
skrawool 0:3954a906acc2 46 * ledport = LED_MASK;
skrawool 0:3954a906acc2 47 * wait(1);
skrawool 0:3954a906acc2 48 * ledport = 0;
skrawool 0:3954a906acc2 49 * wait(1);
skrawool 0:3954a906acc2 50 * }
skrawool 0:3954a906acc2 51 * }
skrawool 0:3954a906acc2 52 * @endcode
skrawool 0:3954a906acc2 53 */
skrawool 0:3954a906acc2 54 class PortOut {
skrawool 0:3954a906acc2 55 public:
skrawool 0:3954a906acc2 56
skrawool 0:3954a906acc2 57 /** Create an PortOut, connected to the specified port
skrawool 0:3954a906acc2 58 *
skrawool 0:3954a906acc2 59 * @param port Port to connect to (Port0-Port5)
skrawool 0:3954a906acc2 60 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
skrawool 0:3954a906acc2 61 */
skrawool 0:3954a906acc2 62 PortOut(PortName port, int mask = 0xFFFFFFFF) {
skrawool 0:3954a906acc2 63 core_util_critical_section_enter();
skrawool 0:3954a906acc2 64 port_init(&_port, port, mask, PIN_OUTPUT);
skrawool 0:3954a906acc2 65 core_util_critical_section_exit();
skrawool 0:3954a906acc2 66 }
skrawool 0:3954a906acc2 67
skrawool 0:3954a906acc2 68 /** Write the value to the output port
skrawool 0:3954a906acc2 69 *
skrawool 0:3954a906acc2 70 * @param value An integer specifying a bit to write for every corresponding PortOut pin
skrawool 0:3954a906acc2 71 */
skrawool 0:3954a906acc2 72 void write(int value) {
skrawool 0:3954a906acc2 73 port_write(&_port, value);
skrawool 0:3954a906acc2 74 }
skrawool 0:3954a906acc2 75
skrawool 0:3954a906acc2 76 /** Read the value currently output on the port
skrawool 0:3954a906acc2 77 *
skrawool 0:3954a906acc2 78 * @returns
skrawool 0:3954a906acc2 79 * An integer with each bit corresponding to associated PortOut pin setting
skrawool 0:3954a906acc2 80 */
skrawool 0:3954a906acc2 81 int read() {
skrawool 0:3954a906acc2 82 return port_read(&_port);
skrawool 0:3954a906acc2 83 }
skrawool 0:3954a906acc2 84
skrawool 0:3954a906acc2 85 /** A shorthand for write()
skrawool 0:3954a906acc2 86 */
skrawool 0:3954a906acc2 87 PortOut& operator= (int value) {
skrawool 0:3954a906acc2 88 write(value);
skrawool 0:3954a906acc2 89 return *this;
skrawool 0:3954a906acc2 90 }
skrawool 0:3954a906acc2 91
skrawool 0:3954a906acc2 92 PortOut& operator= (PortOut& rhs) {
skrawool 0:3954a906acc2 93 write(rhs.read());
skrawool 0:3954a906acc2 94 return *this;
skrawool 0:3954a906acc2 95 }
skrawool 0:3954a906acc2 96
skrawool 0:3954a906acc2 97 /** A shorthand for read()
skrawool 0:3954a906acc2 98 */
skrawool 0:3954a906acc2 99 operator int() {
skrawool 0:3954a906acc2 100 return read();
skrawool 0:3954a906acc2 101 }
skrawool 0:3954a906acc2 102
skrawool 0:3954a906acc2 103 private:
skrawool 0:3954a906acc2 104 port_t _port;
skrawool 0:3954a906acc2 105 };
skrawool 0:3954a906acc2 106
skrawool 0:3954a906acc2 107 } // namespace mbed
skrawool 0:3954a906acc2 108
skrawool 0:3954a906acc2 109 #endif
skrawool 0:3954a906acc2 110
skrawool 0:3954a906acc2 111 #endif
skrawool 0:3954a906acc2 112
skrawool 0:3954a906acc2 113 /** @}*/