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_TIMER_H
skrawool 0:3954a906acc2 17 #define MBED_TIMER_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20 #include "hal/ticker_api.h"
skrawool 0:3954a906acc2 21
skrawool 0:3954a906acc2 22 namespace mbed {
skrawool 0:3954a906acc2 23 /** \addtogroup drivers */
skrawool 0:3954a906acc2 24 /** @{*/
skrawool 0:3954a906acc2 25
skrawool 0:3954a906acc2 26 /** A general purpose timer
skrawool 0:3954a906acc2 27 *
skrawool 0:3954a906acc2 28 * @Note Synchronization level: Interrupt safe
skrawool 0:3954a906acc2 29 *
skrawool 0:3954a906acc2 30 * Example:
skrawool 0:3954a906acc2 31 * @code
skrawool 0:3954a906acc2 32 * // Count the time to toggle a LED
skrawool 0:3954a906acc2 33 *
skrawool 0:3954a906acc2 34 * #include "mbed.h"
skrawool 0:3954a906acc2 35 *
skrawool 0:3954a906acc2 36 * Timer timer;
skrawool 0:3954a906acc2 37 * DigitalOut led(LED1);
skrawool 0:3954a906acc2 38 * int begin, end;
skrawool 0:3954a906acc2 39 *
skrawool 0:3954a906acc2 40 * int main() {
skrawool 0:3954a906acc2 41 * timer.start();
skrawool 0:3954a906acc2 42 * begin = timer.read_us();
skrawool 0:3954a906acc2 43 * led = !led;
skrawool 0:3954a906acc2 44 * end = timer.read_us();
skrawool 0:3954a906acc2 45 * printf("Toggle the led takes %d us", end - begin);
skrawool 0:3954a906acc2 46 * }
skrawool 0:3954a906acc2 47 * @endcode
skrawool 0:3954a906acc2 48 */
skrawool 0:3954a906acc2 49 class Timer {
skrawool 0:3954a906acc2 50
skrawool 0:3954a906acc2 51 public:
skrawool 0:3954a906acc2 52 Timer();
skrawool 0:3954a906acc2 53 Timer(const ticker_data_t *data);
skrawool 0:3954a906acc2 54
skrawool 0:3954a906acc2 55 /** Start the timer
skrawool 0:3954a906acc2 56 */
skrawool 0:3954a906acc2 57 void start();
skrawool 0:3954a906acc2 58
skrawool 0:3954a906acc2 59 /** Stop the timer
skrawool 0:3954a906acc2 60 */
skrawool 0:3954a906acc2 61 void stop();
skrawool 0:3954a906acc2 62
skrawool 0:3954a906acc2 63 /** Reset the timer to 0.
skrawool 0:3954a906acc2 64 *
skrawool 0:3954a906acc2 65 * If it was already counting, it will continue
skrawool 0:3954a906acc2 66 */
skrawool 0:3954a906acc2 67 void reset();
skrawool 0:3954a906acc2 68
skrawool 0:3954a906acc2 69 /** Get the time passed in seconds
skrawool 0:3954a906acc2 70 */
skrawool 0:3954a906acc2 71 float read();
skrawool 0:3954a906acc2 72
skrawool 0:3954a906acc2 73 /** Get the time passed in mili-seconds
skrawool 0:3954a906acc2 74 */
skrawool 0:3954a906acc2 75 int read_ms();
skrawool 0:3954a906acc2 76
skrawool 0:3954a906acc2 77 /** Get the time passed in micro-seconds
skrawool 0:3954a906acc2 78 */
skrawool 0:3954a906acc2 79 int read_us();
skrawool 0:3954a906acc2 80
skrawool 0:3954a906acc2 81 /** An operator shorthand for read()
skrawool 0:3954a906acc2 82 */
skrawool 0:3954a906acc2 83 operator float();
skrawool 0:3954a906acc2 84
skrawool 0:3954a906acc2 85 protected:
skrawool 0:3954a906acc2 86 int slicetime();
skrawool 0:3954a906acc2 87 int _running; // whether the timer is running
skrawool 0:3954a906acc2 88 unsigned int _start; // the start time of the latest slice
skrawool 0:3954a906acc2 89 int _time; // any accumulated time from previous slices
skrawool 0:3954a906acc2 90 const ticker_data_t *_ticker_data;
skrawool 0:3954a906acc2 91 };
skrawool 0:3954a906acc2 92
skrawool 0:3954a906acc2 93 } // namespace mbed
skrawool 0:3954a906acc2 94
skrawool 0:3954a906acc2 95 #endif
skrawool 0:3954a906acc2 96
skrawool 0:3954a906acc2 97 /** @}*/