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_INTERRUPTIN_H
skrawool 0:3954a906acc2 17 #define MBED_INTERRUPTIN_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20
skrawool 0:3954a906acc2 21 #if DEVICE_INTERRUPTIN
skrawool 0:3954a906acc2 22
skrawool 0:3954a906acc2 23 #include "hal/gpio_api.h"
skrawool 0:3954a906acc2 24 #include "hal/gpio_irq_api.h"
skrawool 0:3954a906acc2 25 #include "platform/Callback.h"
skrawool 0:3954a906acc2 26 #include "platform/critical.h"
skrawool 0:3954a906acc2 27 #include "platform/toolchain.h"
skrawool 0:3954a906acc2 28
skrawool 0:3954a906acc2 29 namespace mbed {
skrawool 0:3954a906acc2 30 /** \addtogroup drivers */
skrawool 0:3954a906acc2 31 /** @{*/
skrawool 0:3954a906acc2 32
skrawool 0:3954a906acc2 33 /** A digital interrupt input, used to call a function on a rising or falling edge
skrawool 0:3954a906acc2 34 *
skrawool 0:3954a906acc2 35 * @Note Synchronization level: Interrupt safe
skrawool 0:3954a906acc2 36 *
skrawool 0:3954a906acc2 37 * Example:
skrawool 0:3954a906acc2 38 * @code
skrawool 0:3954a906acc2 39 * // Flash an LED while waiting for events
skrawool 0:3954a906acc2 40 *
skrawool 0:3954a906acc2 41 * #include "mbed.h"
skrawool 0:3954a906acc2 42 *
skrawool 0:3954a906acc2 43 * InterruptIn event(p16);
skrawool 0:3954a906acc2 44 * DigitalOut led(LED1);
skrawool 0:3954a906acc2 45 *
skrawool 0:3954a906acc2 46 * void trigger() {
skrawool 0:3954a906acc2 47 * printf("triggered!\n");
skrawool 0:3954a906acc2 48 * }
skrawool 0:3954a906acc2 49 *
skrawool 0:3954a906acc2 50 * int main() {
skrawool 0:3954a906acc2 51 * event.rise(&trigger);
skrawool 0:3954a906acc2 52 * while(1) {
skrawool 0:3954a906acc2 53 * led = !led;
skrawool 0:3954a906acc2 54 * wait(0.25);
skrawool 0:3954a906acc2 55 * }
skrawool 0:3954a906acc2 56 * }
skrawool 0:3954a906acc2 57 * @endcode
skrawool 0:3954a906acc2 58 */
skrawool 0:3954a906acc2 59 class InterruptIn {
skrawool 0:3954a906acc2 60
skrawool 0:3954a906acc2 61 public:
skrawool 0:3954a906acc2 62
skrawool 0:3954a906acc2 63 /** Create an InterruptIn connected to the specified pin
skrawool 0:3954a906acc2 64 *
skrawool 0:3954a906acc2 65 * @param pin InterruptIn pin to connect to
skrawool 0:3954a906acc2 66 * @param name (optional) A string to identify the object
skrawool 0:3954a906acc2 67 */
skrawool 0:3954a906acc2 68 InterruptIn(PinName pin);
skrawool 0:3954a906acc2 69 virtual ~InterruptIn();
skrawool 0:3954a906acc2 70
skrawool 0:3954a906acc2 71 /** Read the input, represented as 0 or 1 (int)
skrawool 0:3954a906acc2 72 *
skrawool 0:3954a906acc2 73 * @returns
skrawool 0:3954a906acc2 74 * An integer representing the state of the input pin,
skrawool 0:3954a906acc2 75 * 0 for logical 0, 1 for logical 1
skrawool 0:3954a906acc2 76 */
skrawool 0:3954a906acc2 77 int read();
skrawool 0:3954a906acc2 78
skrawool 0:3954a906acc2 79 /** An operator shorthand for read()
skrawool 0:3954a906acc2 80 */
skrawool 0:3954a906acc2 81 operator int();
skrawool 0:3954a906acc2 82
skrawool 0:3954a906acc2 83
skrawool 0:3954a906acc2 84 /** Attach a function to call when a rising edge occurs on the input
skrawool 0:3954a906acc2 85 *
skrawool 0:3954a906acc2 86 * @param func A pointer to a void function, or 0 to set as none
skrawool 0:3954a906acc2 87 */
skrawool 0:3954a906acc2 88 void rise(Callback<void()> func);
skrawool 0:3954a906acc2 89
skrawool 0:3954a906acc2 90 /** Attach a member function to call when a rising edge occurs on the input
skrawool 0:3954a906acc2 91 *
skrawool 0:3954a906acc2 92 * @param obj pointer to the object to call the member function on
skrawool 0:3954a906acc2 93 * @param method pointer to the member function to be called
skrawool 0:3954a906acc2 94 * @deprecated
skrawool 0:3954a906acc2 95 * The rise function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 96 * rise(callback(obj, method)).
skrawool 0:3954a906acc2 97 */
skrawool 0:3954a906acc2 98 template<typename T, typename M>
skrawool 0:3954a906acc2 99 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 100 "The rise function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 101 "rise(callback(obj, method)).")
skrawool 0:3954a906acc2 102 void rise(T *obj, M method) {
skrawool 0:3954a906acc2 103 core_util_critical_section_enter();
skrawool 0:3954a906acc2 104 rise(callback(obj, method));
skrawool 0:3954a906acc2 105 core_util_critical_section_exit();
skrawool 0:3954a906acc2 106 }
skrawool 0:3954a906acc2 107
skrawool 0:3954a906acc2 108 /** Attach a function to call when a falling edge occurs on the input
skrawool 0:3954a906acc2 109 *
skrawool 0:3954a906acc2 110 * @param func A pointer to a void function, or 0 to set as none
skrawool 0:3954a906acc2 111 */
skrawool 0:3954a906acc2 112 void fall(Callback<void()> func);
skrawool 0:3954a906acc2 113
skrawool 0:3954a906acc2 114 /** Attach a member function to call when a falling edge occurs on the input
skrawool 0:3954a906acc2 115 *
skrawool 0:3954a906acc2 116 * @param obj pointer to the object to call the member function on
skrawool 0:3954a906acc2 117 * @param method pointer to the member function to be called
skrawool 0:3954a906acc2 118 * @deprecated
skrawool 0:3954a906acc2 119 * The rise function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 120 * rise(callback(obj, method)).
skrawool 0:3954a906acc2 121 */
skrawool 0:3954a906acc2 122 template<typename T, typename M>
skrawool 0:3954a906acc2 123 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 124 "The fall function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 125 "fall(callback(obj, method)).")
skrawool 0:3954a906acc2 126 void fall(T *obj, M method) {
skrawool 0:3954a906acc2 127 core_util_critical_section_enter();
skrawool 0:3954a906acc2 128 fall(callback(obj, method));
skrawool 0:3954a906acc2 129 core_util_critical_section_exit();
skrawool 0:3954a906acc2 130 }
skrawool 0:3954a906acc2 131
skrawool 0:3954a906acc2 132 /** Set the input pin mode
skrawool 0:3954a906acc2 133 *
skrawool 0:3954a906acc2 134 * @param mode PullUp, PullDown, PullNone
skrawool 0:3954a906acc2 135 */
skrawool 0:3954a906acc2 136 void mode(PinMode pull);
skrawool 0:3954a906acc2 137
skrawool 0:3954a906acc2 138 /** Enable IRQ. This method depends on hw implementation, might enable one
skrawool 0:3954a906acc2 139 * port interrupts. For further information, check gpio_irq_enable().
skrawool 0:3954a906acc2 140 */
skrawool 0:3954a906acc2 141 void enable_irq();
skrawool 0:3954a906acc2 142
skrawool 0:3954a906acc2 143 /** Disable IRQ. This method depends on hw implementation, might disable one
skrawool 0:3954a906acc2 144 * port interrupts. For further information, check gpio_irq_disable().
skrawool 0:3954a906acc2 145 */
skrawool 0:3954a906acc2 146 void disable_irq();
skrawool 0:3954a906acc2 147
skrawool 0:3954a906acc2 148 static void _irq_handler(uint32_t id, gpio_irq_event event);
skrawool 0:3954a906acc2 149
skrawool 0:3954a906acc2 150 protected:
skrawool 0:3954a906acc2 151 gpio_t gpio;
skrawool 0:3954a906acc2 152 gpio_irq_t gpio_irq;
skrawool 0:3954a906acc2 153
skrawool 0:3954a906acc2 154 Callback<void()> _rise;
skrawool 0:3954a906acc2 155 Callback<void()> _fall;
skrawool 0:3954a906acc2 156 };
skrawool 0:3954a906acc2 157
skrawool 0:3954a906acc2 158 } // namespace mbed
skrawool 0:3954a906acc2 159
skrawool 0:3954a906acc2 160 #endif
skrawool 0:3954a906acc2 161
skrawool 0:3954a906acc2 162 #endif
skrawool 0:3954a906acc2 163
skrawool 0:3954a906acc2 164 /** @}*/