software to control a DC motor, preferably interfacing with a motor driver.
DCMotor.h@3:a0dc016b7cbb, 2011-07-15 (annotated)
- Committer:
- kaushalpkk
- Date:
- Fri Jul 15 18:04:43 2011 +0000
- Revision:
- 3:a0dc016b7cbb
- Parent:
- 2:46bca6d9dbda
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaushalpkk | 0:c92be90656b7 | 1 | #ifndef MBED_DCMOTOR_H |
kaushalpkk | 0:c92be90656b7 | 2 | #define MBED_DCMOTOR_H |
kaushalpkk | 0:c92be90656b7 | 3 | |
kaushalpkk | 0:c92be90656b7 | 4 | #include "mbed.h" |
kaushalpkk | 0:c92be90656b7 | 5 | |
kaushalpkk | 3:a0dc016b7cbb | 6 | /**DC motor control class with PWM control |
kaushalpkk | 3:a0dc016b7cbb | 7 | * |
kaushalpkk | 3:a0dc016b7cbb | 8 | * Example: |
kaushalpkk | 3:a0dc016b7cbb | 9 | * @code |
kaushalpkk | 3:a0dc016b7cbb | 10 | * |
kaushalpkk | 3:a0dc016b7cbb | 11 | * #include "mbed.h" |
kaushalpkk | 3:a0dc016b7cbb | 12 | * #include "DCMotor.h" |
kaushalpkk | 3:a0dc016b7cbb | 13 | * |
kaushalpkk | 3:a0dc016b7cbb | 14 | * DCMotor a(p21,p22,p23); |
kaushalpkk | 3:a0dc016b7cbb | 15 | * DCMotor b(p24,p25,p26); |
kaushalpkk | 3:a0dc016b7cbb | 16 | * int main() { |
kaushalpkk | 3:a0dc016b7cbb | 17 | * a.driveIt(50); |
kaushalpkk | 3:a0dc016b7cbb | 18 | * b.driveIt(50); |
kaushalpkk | 3:a0dc016b7cbb | 19 | * } |
kaushalpkk | 3:a0dc016b7cbb | 20 | * |
kaushalpkk | 3:a0dc016b7cbb | 21 | * @endcode |
kaushalpkk | 3:a0dc016b7cbb | 22 | */ |
kaushalpkk | 3:a0dc016b7cbb | 23 | |
kaushalpkk | 0:c92be90656b7 | 24 | class DCMotor { |
kaushalpkk | 0:c92be90656b7 | 25 | |
kaushalpkk | 0:c92be90656b7 | 26 | public: |
kaushalpkk | 1:88772267f757 | 27 | /** create a DCMotor object connected to the pins with speed control |
kaushalpkk | 3:a0dc016b7cbb | 28 | * @param PWMPin PWM pin to control speed of motor |
kaushalpkk | 3:a0dc016b7cbb | 29 | * @param PinA Digital output pin to connect to motor |
kaushalpkk | 3:a0dc016b7cbb | 30 | * @param PinB Digital output pin to connect to motor |
kaushalpkk | 1:88772267f757 | 31 | */ |
kaushalpkk | 0:c92be90656b7 | 32 | DCMotor(PinName PWMPin, PinName PinA, PinName PinB); |
kaushalpkk | 1:88772267f757 | 33 | |
kaushalpkk | 1:88772267f757 | 34 | /** drive Motor input range (-100 to 100). |
kaushalpkk | 3:a0dc016b7cbb | 35 | * @param perCent PWM pin to control speed of motor |
kaushalpkk | 1:88772267f757 | 36 | */ |
kaushalpkk | 0:c92be90656b7 | 37 | void driveIt(float); |
kaushalpkk | 1:88772267f757 | 38 | |
kaushalpkk | 0:c92be90656b7 | 39 | protected: |
kaushalpkk | 0:c92be90656b7 | 40 | PwmOut _PWMPin; |
kaushalpkk | 0:c92be90656b7 | 41 | DigitalOut _PinA; |
kaushalpkk | 0:c92be90656b7 | 42 | DigitalOut _PinB; |
kaushalpkk | 0:c92be90656b7 | 43 | }; |
kaushalpkk | 0:c92be90656b7 | 44 | |
kaushalpkk | 0:c92be90656b7 | 45 | #endif |