SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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