Junaid Ahmed
/
202A_hw1_maxrate
Generate the maximum sampling rate
TSI/TSISensor.h@1:478b36058c92, 2014-02-15 (annotated)
- Committer:
- mja054
- Date:
- Sat Feb 15 01:07:15 2014 +0000
- Revision:
- 1:478b36058c92
- Parent:
- 0:d62b58e30f71
Generate the maximum sampling rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mja054 | 0:d62b58e30f71 | 1 | /* Freescale Semiconductor Inc. |
mja054 | 0:d62b58e30f71 | 2 | * (c) Copyright 2004-2005 Freescale Semiconductor, Inc. |
mja054 | 0:d62b58e30f71 | 3 | * (c) Copyright 2001-2004 Motorola, Inc. |
mja054 | 0:d62b58e30f71 | 4 | * |
mja054 | 0:d62b58e30f71 | 5 | * mbed Microcontroller Library |
mja054 | 0:d62b58e30f71 | 6 | * (c) Copyright 2009-2012 ARM Limited. |
mja054 | 0:d62b58e30f71 | 7 | * |
mja054 | 0:d62b58e30f71 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mja054 | 0:d62b58e30f71 | 9 | * and associated documentation files (the "Software"), to deal in the Software without |
mja054 | 0:d62b58e30f71 | 10 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
mja054 | 0:d62b58e30f71 | 11 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
mja054 | 0:d62b58e30f71 | 12 | * Software is furnished to do so, subject to the following conditions: |
mja054 | 0:d62b58e30f71 | 13 | * |
mja054 | 0:d62b58e30f71 | 14 | * The above copyright notice and this permission notice shall be included in all copies or |
mja054 | 0:d62b58e30f71 | 15 | * substantial portions of the Software. |
mja054 | 0:d62b58e30f71 | 16 | * |
mja054 | 0:d62b58e30f71 | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mja054 | 0:d62b58e30f71 | 18 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mja054 | 0:d62b58e30f71 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mja054 | 0:d62b58e30f71 | 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mja054 | 0:d62b58e30f71 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mja054 | 0:d62b58e30f71 | 22 | */ |
mja054 | 0:d62b58e30f71 | 23 | |
mja054 | 0:d62b58e30f71 | 24 | #ifndef TSISENSOR_H |
mja054 | 0:d62b58e30f71 | 25 | #define TSISENSOR_H |
mja054 | 0:d62b58e30f71 | 26 | |
mja054 | 0:d62b58e30f71 | 27 | /** |
mja054 | 0:d62b58e30f71 | 28 | * TSISensor example |
mja054 | 0:d62b58e30f71 | 29 | * |
mja054 | 0:d62b58e30f71 | 30 | * @code |
mja054 | 0:d62b58e30f71 | 31 | * #include "mbed.h" |
mja054 | 0:d62b58e30f71 | 32 | * #include "TSISensor.h" |
mja054 | 0:d62b58e30f71 | 33 | * |
mja054 | 0:d62b58e30f71 | 34 | * int main(void) { |
mja054 | 0:d62b58e30f71 | 35 | * PwmOut led(LED_GREEN); |
mja054 | 0:d62b58e30f71 | 36 | * TSISensor tsi; |
mja054 | 0:d62b58e30f71 | 37 | * |
mja054 | 0:d62b58e30f71 | 38 | * while (true) { |
mja054 | 0:d62b58e30f71 | 39 | * led = 1.0 - tsi.readPercentage(); |
mja054 | 0:d62b58e30f71 | 40 | * wait(0.1); |
mja054 | 0:d62b58e30f71 | 41 | * } |
mja054 | 0:d62b58e30f71 | 42 | * } |
mja054 | 0:d62b58e30f71 | 43 | * @endcode |
mja054 | 0:d62b58e30f71 | 44 | */ |
mja054 | 0:d62b58e30f71 | 45 | class TSISensor { |
mja054 | 0:d62b58e30f71 | 46 | public: |
mja054 | 0:d62b58e30f71 | 47 | /** |
mja054 | 0:d62b58e30f71 | 48 | * Initialize the TSI Touch Sensor |
mja054 | 0:d62b58e30f71 | 49 | */ |
mja054 | 0:d62b58e30f71 | 50 | TSISensor(); |
mja054 | 0:d62b58e30f71 | 51 | |
mja054 | 0:d62b58e30f71 | 52 | /** |
mja054 | 0:d62b58e30f71 | 53 | * Read Touch Sensor percentage value |
mja054 | 0:d62b58e30f71 | 54 | * |
mja054 | 0:d62b58e30f71 | 55 | * @returns percentage value between [0 ... 1] |
mja054 | 0:d62b58e30f71 | 56 | */ |
mja054 | 0:d62b58e30f71 | 57 | float readPercentage(); |
mja054 | 0:d62b58e30f71 | 58 | |
mja054 | 0:d62b58e30f71 | 59 | /** |
mja054 | 0:d62b58e30f71 | 60 | * Read Touch Sensor distance |
mja054 | 0:d62b58e30f71 | 61 | * |
mja054 | 0:d62b58e30f71 | 62 | * @returns distance in mm. The value is between [0 ... 40] |
mja054 | 0:d62b58e30f71 | 63 | */ |
mja054 | 0:d62b58e30f71 | 64 | uint8_t readDistance(); |
mja054 | 0:d62b58e30f71 | 65 | uint16_t readValue(uint8_t); |
mja054 | 0:d62b58e30f71 | 66 | void TSISensor_reset(void); |
mja054 | 0:d62b58e30f71 | 67 | |
mja054 | 0:d62b58e30f71 | 68 | private: |
mja054 | 0:d62b58e30f71 | 69 | void sliderRead(void); |
mja054 | 0:d62b58e30f71 | 70 | void selfCalibration(void); |
mja054 | 0:d62b58e30f71 | 71 | }; |
mja054 | 0:d62b58e30f71 | 72 | |
mja054 | 0:d62b58e30f71 | 73 | #endif |