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_TICKER_H
skrawool 0:3954a906acc2 17 #define MBED_TICKER_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "drivers/TimerEvent.h"
skrawool 0:3954a906acc2 20 #include "platform/Callback.h"
skrawool 0:3954a906acc2 21 #include "platform/toolchain.h"
skrawool 0:3954a906acc2 22
skrawool 0:3954a906acc2 23 namespace mbed {
skrawool 0:3954a906acc2 24 /** \addtogroup drivers */
skrawool 0:3954a906acc2 25 /** @{*/
skrawool 0:3954a906acc2 26
skrawool 0:3954a906acc2 27 /** A Ticker is used to call a function at a recurring interval
skrawool 0:3954a906acc2 28 *
skrawool 0:3954a906acc2 29 * You can use as many seperate Ticker objects as you require.
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 the blinking led after 5 seconds
skrawool 0:3954a906acc2 36 *
skrawool 0:3954a906acc2 37 * #include "mbed.h"
skrawool 0:3954a906acc2 38 *
skrawool 0:3954a906acc2 39 * Ticker timer;
skrawool 0:3954a906acc2 40 * DigitalOut led1(LED1);
skrawool 0:3954a906acc2 41 * DigitalOut led2(LED2);
skrawool 0:3954a906acc2 42 *
skrawool 0:3954a906acc2 43 * int flip = 0;
skrawool 0:3954a906acc2 44 *
skrawool 0:3954a906acc2 45 * void attime() {
skrawool 0:3954a906acc2 46 * flip = !flip;
skrawool 0:3954a906acc2 47 * }
skrawool 0:3954a906acc2 48 *
skrawool 0:3954a906acc2 49 * int main() {
skrawool 0:3954a906acc2 50 * timer.attach(&attime, 5);
skrawool 0:3954a906acc2 51 * while(1) {
skrawool 0:3954a906acc2 52 * if(flip == 0) {
skrawool 0:3954a906acc2 53 * led1 = !led1;
skrawool 0:3954a906acc2 54 * } else {
skrawool 0:3954a906acc2 55 * led2 = !led2;
skrawool 0:3954a906acc2 56 * }
skrawool 0:3954a906acc2 57 * wait(0.2);
skrawool 0:3954a906acc2 58 * }
skrawool 0:3954a906acc2 59 * }
skrawool 0:3954a906acc2 60 * @endcode
skrawool 0:3954a906acc2 61 */
skrawool 0:3954a906acc2 62 class Ticker : public TimerEvent {
skrawool 0:3954a906acc2 63
skrawool 0:3954a906acc2 64 public:
skrawool 0:3954a906acc2 65 Ticker() : TimerEvent() {
skrawool 0:3954a906acc2 66 }
skrawool 0:3954a906acc2 67
skrawool 0:3954a906acc2 68 Ticker(const ticker_data_t *data) : TimerEvent(data) {
skrawool 0:3954a906acc2 69 data->interface->init();
skrawool 0:3954a906acc2 70 }
skrawool 0:3954a906acc2 71
skrawool 0:3954a906acc2 72 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
skrawool 0:3954a906acc2 73 *
skrawool 0:3954a906acc2 74 * @param func pointer to the function to be called
skrawool 0:3954a906acc2 75 * @param t the time between calls in seconds
skrawool 0:3954a906acc2 76 */
skrawool 0:3954a906acc2 77 void attach(Callback<void()> func, float t) {
skrawool 0:3954a906acc2 78 attach_us(func, t * 1000000.0f);
skrawool 0:3954a906acc2 79 }
skrawool 0:3954a906acc2 80
skrawool 0:3954a906acc2 81 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
skrawool 0:3954a906acc2 82 *
skrawool 0:3954a906acc2 83 * @param obj pointer to the object to call the member function on
skrawool 0:3954a906acc2 84 * @param method pointer to the member function to be called
skrawool 0:3954a906acc2 85 * @param t the time between calls in seconds
skrawool 0:3954a906acc2 86 * @deprecated
skrawool 0:3954a906acc2 87 * The attach function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 88 * attach(callback(obj, method), t).
skrawool 0:3954a906acc2 89 */
skrawool 0:3954a906acc2 90 template<typename T, typename M>
skrawool 0:3954a906acc2 91 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 92 "The attach function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 93 "attach(callback(obj, method), t).")
skrawool 0:3954a906acc2 94 void attach(T *obj, M method, float t) {
skrawool 0:3954a906acc2 95 attach(callback(obj, method), t);
skrawool 0:3954a906acc2 96 }
skrawool 0:3954a906acc2 97
skrawool 0:3954a906acc2 98 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
skrawool 0:3954a906acc2 99 *
skrawool 0:3954a906acc2 100 * @param fptr pointer to the function to be called
skrawool 0:3954a906acc2 101 * @param t the time between calls in micro-seconds
skrawool 0:3954a906acc2 102 */
skrawool 0:3954a906acc2 103 void attach_us(Callback<void()> func, timestamp_t t) {
skrawool 0:3954a906acc2 104 _function.attach(func);
skrawool 0:3954a906acc2 105 setup(t);
skrawool 0:3954a906acc2 106 }
skrawool 0:3954a906acc2 107
skrawool 0:3954a906acc2 108 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
skrawool 0:3954a906acc2 109 *
skrawool 0:3954a906acc2 110 * @param tptr pointer to the object to call the member function on
skrawool 0:3954a906acc2 111 * @param mptr pointer to the member function to be called
skrawool 0:3954a906acc2 112 * @param t the time between calls in micro-seconds
skrawool 0:3954a906acc2 113 * @deprecated
skrawool 0:3954a906acc2 114 * The attach_us function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 115 * attach_us(callback(obj, method), t).
skrawool 0:3954a906acc2 116 */
skrawool 0:3954a906acc2 117 template<typename T, typename M>
skrawool 0:3954a906acc2 118 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 119 "The attach_us function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 120 "attach_us(callback(obj, method), t).")
skrawool 0:3954a906acc2 121 void attach_us(T *obj, M method, timestamp_t t) {
skrawool 0:3954a906acc2 122 attach_us(Callback<void()>(obj, method), t);
skrawool 0:3954a906acc2 123 }
skrawool 0:3954a906acc2 124
skrawool 0:3954a906acc2 125 virtual ~Ticker() {
skrawool 0:3954a906acc2 126 detach();
skrawool 0:3954a906acc2 127 }
skrawool 0:3954a906acc2 128
skrawool 0:3954a906acc2 129 /** Detach the function
skrawool 0:3954a906acc2 130 */
skrawool 0:3954a906acc2 131 void detach();
skrawool 0:3954a906acc2 132
skrawool 0:3954a906acc2 133 protected:
skrawool 0:3954a906acc2 134 void setup(timestamp_t t);
skrawool 0:3954a906acc2 135 virtual void handler();
skrawool 0:3954a906acc2 136
skrawool 0:3954a906acc2 137 protected:
skrawool 0:3954a906acc2 138 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
skrawool 0:3954a906acc2 139 Callback<void()> _function; /**< Callback. */
skrawool 0:3954a906acc2 140 };
skrawool 0:3954a906acc2 141
skrawool 0:3954a906acc2 142 } // namespace mbed
skrawool 0:3954a906acc2 143
skrawool 0:3954a906acc2 144 #endif
skrawool 0:3954a906acc2 145
skrawool 0:3954a906acc2 146 /** @}*/