Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more
GP2A.cpp@4:4f443a6a6843, 2018-05-31 (annotated)
- Committer:
- haarkon
- Date:
- Thu May 31 17:25:25 2018 +0000
- Revision:
- 4:4f443a6a6843
- Parent:
- 2:5e591a5b8edd
- Child:
- 5:49fb7016797c
Tested GP2A library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| haarkon | 0:17de10d278c2 | 1 | #include "GP2A.h" |
| haarkon | 0:17de10d278c2 | 2 | |
| haarkon | 0:17de10d278c2 | 3 | GP2A::GP2A(PinName vmes, float dMin, float dMax, float slope) : _sensor(vmes) |
| haarkon | 0:17de10d278c2 | 4 | { |
| haarkon | 0:17de10d278c2 | 5 | m_dMin = dMin; |
| haarkon | 0:17de10d278c2 | 6 | m_dMax = dMax; |
| haarkon | 0:17de10d278c2 | 7 | m_slope = slope; |
| haarkon | 0:17de10d278c2 | 8 | } |
| haarkon | 0:17de10d278c2 | 9 | |
| haarkon | 2:5e591a5b8edd | 10 | double GP2A::getDistance (void) |
| haarkon | 0:17de10d278c2 | 11 | { |
| haarkon | 4:4f443a6a6843 | 12 | double vDist = (double)_sensor.read()* 3.3; |
| haarkon | 0:17de10d278c2 | 13 | float distance = m_slope/vDist; |
| haarkon | 0:17de10d278c2 | 14 | if (distance > m_dMax) return m_dMax; |
| haarkon | 0:17de10d278c2 | 15 | if (distance < m_dMin) return m_dMin; |
| haarkon | 0:17de10d278c2 | 16 | return distance; |
| haarkon | 0:17de10d278c2 | 17 | } |
| haarkon | 0:17de10d278c2 | 18 | |
| haarkon | 2:5e591a5b8edd | 19 | double GP2A::getVoltage (void) |
| haarkon | 0:17de10d278c2 | 20 | { |
| haarkon | 4:4f443a6a6843 | 21 | return (double)_sensor.read()* 3.3; |
| haarkon | 2:5e591a5b8edd | 22 | } |
| haarkon | 2:5e591a5b8edd | 23 | |
| haarkon | 2:5e591a5b8edd | 24 | GP2A::operator double() { |
| haarkon | 2:5e591a5b8edd | 25 | return getDistance(); |
| haarkon | 2:5e591a5b8edd | 26 | } |