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