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