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