Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
aziz111
Date:
Fri Mar 08 17:15:02 2019 +0000
Revision:
5:569a4894abc1
Parent:
3:78f223d34f36
Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ethaderu 3:78f223d34f36 1 /* mbed Microcontroller Library
ethaderu 3:78f223d34f36 2 * Copyright (c) 2006-2013 ARM Limited
ethaderu 3:78f223d34f36 3 *
ethaderu 3:78f223d34f36 4 * Licensed under the Apache License, Version 2.0 (the "License");
ethaderu 3:78f223d34f36 5 * you may not use this file except in compliance with the License.
ethaderu 3:78f223d34f36 6 * You may obtain a copy of the License at
ethaderu 3:78f223d34f36 7 *
ethaderu 3:78f223d34f36 8 * http://www.apache.org/licenses/LICENSE-2.0
ethaderu 3:78f223d34f36 9 *
ethaderu 3:78f223d34f36 10 * Unless required by applicable law or agreed to in writing, software
ethaderu 3:78f223d34f36 11 * distributed under the License is distributed on an "AS IS" BASIS,
ethaderu 3:78f223d34f36 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ethaderu 3:78f223d34f36 13 * See the License for the specific language governing permissions and
ethaderu 3:78f223d34f36 14 * limitations under the License.
ethaderu 3:78f223d34f36 15 */
ethaderu 3:78f223d34f36 16 #ifndef MBED_ANALOGIN_H
ethaderu 3:78f223d34f36 17 #define MBED_ANALOGIN_H
ethaderu 3:78f223d34f36 18
ethaderu 3:78f223d34f36 19 #include "platform.h"
ethaderu 3:78f223d34f36 20
ethaderu 3:78f223d34f36 21 #if DEVICE_ANALOGIN
ethaderu 3:78f223d34f36 22
ethaderu 3:78f223d34f36 23 #include "analogin_api.h"
ethaderu 3:78f223d34f36 24
ethaderu 3:78f223d34f36 25 namespace mbed {
ethaderu 3:78f223d34f36 26
ethaderu 3:78f223d34f36 27 /** An analog input, used for reading the voltage on a pin
ethaderu 3:78f223d34f36 28 *
ethaderu 3:78f223d34f36 29 * Example:
ethaderu 3:78f223d34f36 30 * @code
ethaderu 3:78f223d34f36 31 * // Print messages when the AnalogIn is greater than 50%
ethaderu 3:78f223d34f36 32 *
ethaderu 3:78f223d34f36 33 * #include "mbed.h"
ethaderu 3:78f223d34f36 34 *
ethaderu 3:78f223d34f36 35 * AnalogIn temperature(p20);
ethaderu 3:78f223d34f36 36 *
ethaderu 3:78f223d34f36 37 * int main() {
ethaderu 3:78f223d34f36 38 * while(1) {
ethaderu 3:78f223d34f36 39 * if(temperature > 0.5) {
ethaderu 3:78f223d34f36 40 * printf("Too hot! (%f)", temperature.read());
ethaderu 3:78f223d34f36 41 * }
ethaderu 3:78f223d34f36 42 * }
ethaderu 3:78f223d34f36 43 * }
ethaderu 3:78f223d34f36 44 * @endcode
ethaderu 3:78f223d34f36 45 */
ethaderu 3:78f223d34f36 46 class AnalogIn {
ethaderu 3:78f223d34f36 47
ethaderu 3:78f223d34f36 48 public:
ethaderu 3:78f223d34f36 49
ethaderu 3:78f223d34f36 50 /** Create an AnalogIn, connected to the specified pin
ethaderu 3:78f223d34f36 51 *
ethaderu 3:78f223d34f36 52 * @param pin AnalogIn pin to connect to
ethaderu 3:78f223d34f36 53 * @param name (optional) A string to identify the object
ethaderu 3:78f223d34f36 54 */
ethaderu 3:78f223d34f36 55 AnalogIn(PinName pin) {
ethaderu 3:78f223d34f36 56 analogin_init(&_adc, pin);
ethaderu 3:78f223d34f36 57 }
ethaderu 3:78f223d34f36 58
ethaderu 3:78f223d34f36 59 /** Read the input voltage, represented as a float in the range [0.0, 1.0]
ethaderu 3:78f223d34f36 60 *
ethaderu 3:78f223d34f36 61 * @returns A floating-point value representing the current input voltage, measured as a percentage
ethaderu 3:78f223d34f36 62 */
ethaderu 3:78f223d34f36 63 float read() {
ethaderu 3:78f223d34f36 64 return analogin_read(&_adc);
ethaderu 3:78f223d34f36 65 }
ethaderu 3:78f223d34f36 66
ethaderu 3:78f223d34f36 67 /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
ethaderu 3:78f223d34f36 68 *
ethaderu 3:78f223d34f36 69 * @returns
ethaderu 3:78f223d34f36 70 * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
ethaderu 3:78f223d34f36 71 */
ethaderu 3:78f223d34f36 72 unsigned short read_u16() {
ethaderu 3:78f223d34f36 73 return analogin_read_u16(&_adc);
ethaderu 3:78f223d34f36 74 }
ethaderu 3:78f223d34f36 75
ethaderu 3:78f223d34f36 76 #ifdef MBED_OPERATORS
ethaderu 3:78f223d34f36 77 /** An operator shorthand for read()
ethaderu 3:78f223d34f36 78 *
ethaderu 3:78f223d34f36 79 * The float() operator can be used as a shorthand for read() to simplify common code sequences
ethaderu 3:78f223d34f36 80 *
ethaderu 3:78f223d34f36 81 * Example:
ethaderu 3:78f223d34f36 82 * @code
ethaderu 3:78f223d34f36 83 * float x = volume.read();
ethaderu 3:78f223d34f36 84 * float x = volume;
ethaderu 3:78f223d34f36 85 *
ethaderu 3:78f223d34f36 86 * if(volume.read() > 0.25) { ... }
ethaderu 3:78f223d34f36 87 * if(volume > 0.25) { ... }
ethaderu 3:78f223d34f36 88 * @endcode
ethaderu 3:78f223d34f36 89 */
ethaderu 3:78f223d34f36 90 operator float() {
ethaderu 3:78f223d34f36 91 return read();
ethaderu 3:78f223d34f36 92 }
ethaderu 3:78f223d34f36 93 #endif
ethaderu 3:78f223d34f36 94
ethaderu 3:78f223d34f36 95 protected:
ethaderu 3:78f223d34f36 96 analogin_t _adc;
ethaderu 3:78f223d34f36 97 };
ethaderu 3:78f223d34f36 98
ethaderu 3:78f223d34f36 99 } // namespace mbed
ethaderu 3:78f223d34f36 100
ethaderu 3:78f223d34f36 101 #endif
ethaderu 3:78f223d34f36 102
ethaderu 3:78f223d34f36 103 #endif