Testcode for LVC Robot club

Dependencies:   mbed

Committer:
jonmarsh
Date:
Mon Apr 23 09:32:50 2012 +0000
Revision:
1:fe52aa73cd6a
Parent:
0:f4922a2a0292

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jonmarsh 0:f4922a2a0292 1 #ifndef SHARPDIGIDIST100_H
jonmarsh 0:f4922a2a0292 2 #define SHARPDIGIDIST100_H
jonmarsh 0:f4922a2a0292 3
jonmarsh 0:f4922a2a0292 4 #include "mbed.h"
jonmarsh 0:f4922a2a0292 5
jonmarsh 0:f4922a2a0292 6 /** A class which interfaces with a Sharp Digital Distance sensor (GP2Y0D810)
jonmarsh 0:f4922a2a0292 7 *
jonmarsh 0:f4922a2a0292 8 * Example:
jonmarsh 0:f4922a2a0292 9 * @code
jonmarsh 0:f4922a2a0292 10 *
jonmarsh 0:f4922a2a0292 11 * @endcode
jonmarsh 0:f4922a2a0292 12 *
jonmarsh 0:f4922a2a0292 13 */
jonmarsh 0:f4922a2a0292 14
jonmarsh 0:f4922a2a0292 15 class SharpDigiDist100
jonmarsh 0:f4922a2a0292 16 {
jonmarsh 0:f4922a2a0292 17 public:
jonmarsh 0:f4922a2a0292 18
jonmarsh 0:f4922a2a0292 19 /** Create a sensor input
jonmarsh 0:f4922a2a0292 20 *
jonmarsh 0:f4922a2a0292 21 * @param pin The pin the output of the sensor is connected to
jonmarsh 0:f4922a2a0292 22 */
jonmarsh 0:f4922a2a0292 23
jonmarsh 0:f4922a2a0292 24 SharpDigiDist100(PinName pin);
jonmarsh 0:f4922a2a0292 25
jonmarsh 0:f4922a2a0292 26 /** The enum which makes up the output
jonmarsh 0:f4922a2a0292 27 *
jonmarsh 0:f4922a2a0292 28 */
jonmarsh 0:f4922a2a0292 29
jonmarsh 0:f4922a2a0292 30 enum Distance
jonmarsh 0:f4922a2a0292 31 {
jonmarsh 0:f4922a2a0292 32 Near = 1,
jonmarsh 0:f4922a2a0292 33 Mid,
jonmarsh 0:f4922a2a0292 34 Far
jonmarsh 0:f4922a2a0292 35 };
jonmarsh 0:f4922a2a0292 36
jonmarsh 0:f4922a2a0292 37 /** Returns the distace as an enum
jonmarsh 0:f4922a2a0292 38 *
jonmarsh 0:f4922a2a0292 39 * @return The distance code: 1 is near, 2 is middle distance and 3 is far
jonmarsh 0:f4922a2a0292 40 */
jonmarsh 0:f4922a2a0292 41
jonmarsh 0:f4922a2a0292 42 int getDistance();
jonmarsh 0:f4922a2a0292 43
jonmarsh 0:f4922a2a0292 44 /** Attaches a function which is called on distance change
jonmarsh 0:f4922a2a0292 45 *
jonmarsh 0:f4922a2a0292 46 * @param A pointer to a function with params/returns: void func(void)
jonmarsh 0:f4922a2a0292 47 */
jonmarsh 0:f4922a2a0292 48
jonmarsh 0:f4922a2a0292 49 void attachOnChange(void (*ptr) (void));
jonmarsh 0:f4922a2a0292 50
jonmarsh 0:f4922a2a0292 51
jonmarsh 0:f4922a2a0292 52 protected:
jonmarsh 0:f4922a2a0292 53
jonmarsh 0:f4922a2a0292 54 InterruptIn intin;
jonmarsh 0:f4922a2a0292 55
jonmarsh 0:f4922a2a0292 56 DigitalIn pinin;
jonmarsh 0:f4922a2a0292 57
jonmarsh 0:f4922a2a0292 58 Timer timer1;
jonmarsh 0:f4922a2a0292 59
jonmarsh 0:f4922a2a0292 60 enum Distance current;
jonmarsh 0:f4922a2a0292 61
jonmarsh 0:f4922a2a0292 62 enum Distance last;
jonmarsh 0:f4922a2a0292 63
jonmarsh 0:f4922a2a0292 64 void onInt();
jonmarsh 0:f4922a2a0292 65
jonmarsh 0:f4922a2a0292 66 Timeout timeout;
jonmarsh 0:f4922a2a0292 67
jonmarsh 0:f4922a2a0292 68 void (*onChange) (void);
jonmarsh 0:f4922a2a0292 69
jonmarsh 0:f4922a2a0292 70 bool onChangeAttached;
jonmarsh 0:f4922a2a0292 71
jonmarsh 0:f4922a2a0292 72 //DigitalOut Debug;
jonmarsh 0:f4922a2a0292 73 };
jonmarsh 0:f4922a2a0292 74
jonmarsh 0:f4922a2a0292 75 #endif