Grove soundsensor lib
soundsensor.h@9:c38836e5d1f5, 2019-01-23 (annotated)
- Committer:
- math991e
- Date:
- Wed Jan 23 11:48:11 2019 +0000
- Revision:
- 9:c38836e5d1f5
- Parent:
- 8:5b4b258eb1da
array fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
math991e | 0:18d442efc99a | 1 | /** |
math991e | 8:5b4b258eb1da | 2 | * |
math991e | 8:5b4b258eb1da | 3 | * @file soundsensor.h |
math991e | 8:5b4b258eb1da | 4 | * @brief supposed to get analogin and change input to Db, but the logic dont seem to work. |
math991e | 8:5b4b258eb1da | 5 | * |
math991e | 8:5b4b258eb1da | 6 | * @author Nikolaj M. & Mathias R. |
math991e | 8:5b4b258eb1da | 7 | * |
math991e | 8:5b4b258eb1da | 8 | * @date 23/1/2019 |
math991e | 8:5b4b258eb1da | 9 | * |
math991e | 8:5b4b258eb1da | 10 | *-----EXAMPLE----- |
math991e | 0:18d442efc99a | 11 | *#include "mbed.h" |
math991e | 0:18d442efc99a | 12 | *#include "soundsensor.h" |
math991e | 0:18d442efc99a | 13 | *soundsensor sound(A0); |
math991e | 0:18d442efc99a | 14 | *bool toDb = true; |
math991e | 0:18d442efc99a | 15 | * |
math991e | 0:18d442efc99a | 16 | *int main() |
math991e | 0:18d442efc99a | 17 | *{ |
math991e | 0:18d442efc99a | 18 | * while (true) { |
math991e | 0:18d442efc99a | 19 | * printf("Loudness: %f\r\n", sound.listen(toDb)); |
math991e | 0:18d442efc99a | 20 | * wait(0.5); |
math991e | 0:18d442efc99a | 21 | * } |
math991e | 0:18d442efc99a | 22 | *} |
math991e | 8:5b4b258eb1da | 23 | *-----EXAMPLE----- |
math991e | 0:18d442efc99a | 24 | **/ |
math991e | 0:18d442efc99a | 25 | |
math991e | 2:d006df643844 | 26 | //Version mbed: 164 |
math991e | 8:5b4b258eb1da | 27 | //PROGRAM: SoundSensor |
math991e | 0:18d442efc99a | 28 | #ifndef SOUNDSENSOR |
math991e | 0:18d442efc99a | 29 | #define SOUNDSENSOR |
math991e | 1:29daa2bdd0c6 | 30 | #include "mbed.h" |
math991e | 0:18d442efc99a | 31 | |
math991e | 8:5b4b258eb1da | 32 | ///SoundSensor CLASS |
math991e | 0:18d442efc99a | 33 | class soundsensor{ |
math991e | 8:5b4b258eb1da | 34 | ///INITIALIZE VARIABLES USED IN CLASS |
math991e | 0:18d442efc99a | 35 | private: |
math991e | 0:18d442efc99a | 36 | PinName _pin; |
math991e | 8:5b4b258eb1da | 37 | ///FUNCTIONS AND CONSTRUCTOR |
math991e | 0:18d442efc99a | 38 | public: |
math991e | 0:18d442efc99a | 39 | soundsensor(PinName); |
math991e | 1:29daa2bdd0c6 | 40 | void setPin(PinName pin); |
math991e | 0:18d442efc99a | 41 | PinName getPin(); |
math991e | 0:18d442efc99a | 42 | float convertToDb(float); |
math991e | 0:18d442efc99a | 43 | float revertFromDb(float); |
math991e | 1:29daa2bdd0c6 | 44 | float listen(bool toDb); |
math991e | 1:29daa2bdd0c6 | 45 | }; |
math991e | 0:18d442efc99a | 46 | |
math991e | 0:18d442efc99a | 47 | #endif |