libary to return a range for sharp IR rangefinders. values are taken from the datasheet. note this is not accurate, but is good enough for seeing if things work

Dependents:   GP2D12rangefinder Initialmbedrobotprogram mbedrobot

Committer:
littlexc
Date:
Thu Nov 25 15:06:32 2010 +0000
Revision:
1:e3ea40a41d27
Parent:
0:28b9e26e75ac

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
littlexc 0:28b9e26e75ac 1 /*Libary for GP2D120
littlexc 0:28b9e26e75ac 2 *
littlexc 0:28b9e26e75ac 3 *
littlexc 0:28b9e26e75ac 4 * by Christopher Hasler.
littlexc 0:28b9e26e75ac 5 *
littlexc 0:28b9e26e75ac 6 *
littlexc 0:28b9e26e75ac 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
littlexc 0:28b9e26e75ac 8 * of this software and associated documentation files (the "Software"), to deal
littlexc 0:28b9e26e75ac 9 * in the Software without restriction, including without limitation the rights
littlexc 0:28b9e26e75ac 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
littlexc 0:28b9e26e75ac 11 * copies of the Software, and to permit persons to whom the Software is
littlexc 0:28b9e26e75ac 12 * furnished to do so, subject to the following conditions:
littlexc 0:28b9e26e75ac 13 *
littlexc 0:28b9e26e75ac 14 * The above copyright notice and this permission notice shall be included in
littlexc 0:28b9e26e75ac 15 * all copies or substantial portions of the Software.
littlexc 0:28b9e26e75ac 16 *
littlexc 0:28b9e26e75ac 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
littlexc 0:28b9e26e75ac 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
littlexc 0:28b9e26e75ac 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
littlexc 0:28b9e26e75ac 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
littlexc 0:28b9e26e75ac 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
littlexc 0:28b9e26e75ac 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
littlexc 0:28b9e26e75ac 23 * THE SOFTWARE.
littlexc 0:28b9e26e75ac 24 */
littlexc 0:28b9e26e75ac 25
littlexc 0:28b9e26e75ac 26 #ifndef MBED_IRRangeFinder_H
littlexc 0:28b9e26e75ac 27 #define MBED_IRRangeFinder_H
littlexc 0:28b9e26e75ac 28 #include "mbed.h"
littlexc 0:28b9e26e75ac 29 /** class to control an IR range finder
littlexc 0:28b9e26e75ac 30 */
littlexc 0:28b9e26e75ac 31 class IRRangeFinder {
littlexc 0:28b9e26e75ac 32
littlexc 0:28b9e26e75ac 33 public:
littlexc 0:28b9e26e75ac 34 /** creates a IR range finder interface
littlexc 0:28b9e26e75ac 35 *
littlexc 0:28b9e26e75ac 36 * @param pin An Analog pin, the data line of the sensor is attached to
littlexc 0:28b9e26e75ac 37 * @param type, deafult 1, GP2D120, 2, GP2D12
littlexc 0:28b9e26e75ac 38 */
littlexc 0:28b9e26e75ac 39 IRRangeFinder (PinName pin, int type = 1);
littlexc 0:28b9e26e75ac 40
littlexc 0:28b9e26e75ac 41 /** returns value for range, greater than; note, scans from max to min.
littlexc 0:28b9e26e75ac 42 * feel free to invert the order to scan from min to max if required
littlexc 0:28b9e26e75ac 43 */
littlexc 0:28b9e26e75ac 44 int read(void);
littlexc 0:28b9e26e75ac 45
littlexc 0:28b9e26e75ac 46 /** returns value for float, read from analog in.
littlexc 0:28b9e26e75ac 47 */
littlexc 0:28b9e26e75ac 48 float read_f(void);
littlexc 0:28b9e26e75ac 49
littlexc 0:28b9e26e75ac 50 /** returns value for voltage
littlexc 0:28b9e26e75ac 51 */
littlexc 0:28b9e26e75ac 52 float read_v(void);
littlexc 0:28b9e26e75ac 53
littlexc 0:28b9e26e75ac 54
littlexc 0:28b9e26e75ac 55 protected:
littlexc 0:28b9e26e75ac 56
littlexc 0:28b9e26e75ac 57 AnalogIn _pin;
littlexc 0:28b9e26e75ac 58 int sensor;
littlexc 0:28b9e26e75ac 59
littlexc 0:28b9e26e75ac 60 };
littlexc 0:28b9e26e75ac 61 #endif