software to control a DC motor, preferably interfacing with a motor driver.
DCMotor.cpp@1:88772267f757, 2011-07-15 (annotated)
- Committer:
- kaushalpkk
- Date:
- Fri Jul 15 17:56:07 2011 +0000
- Revision:
- 1:88772267f757
- Parent:
- 0:c92be90656b7
Used Doxygen for documenting the library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaushalpkk | 0:c92be90656b7 | 1 | #include "DCMotor.h" |
kaushalpkk | 0:c92be90656b7 | 2 | #include "mbed.h" |
kaushalpkk | 0:c92be90656b7 | 3 | |
kaushalpkk | 0:c92be90656b7 | 4 | DCMotor::DCMotor(PinName PWMPin, PinName PinA, PinName PinB): |
kaushalpkk | 1:88772267f757 | 5 | _PWMPin(PWMPin), _PinA(PinA), _PinB(PinB) { |
kaushalpkk | 1:88772267f757 | 6 | |
kaushalpkk | 0:c92be90656b7 | 7 | _PWMPin.period(0.001); |
kaushalpkk | 0:c92be90656b7 | 8 | _PWMPin = 0; |
kaushalpkk | 1:88772267f757 | 9 | |
kaushalpkk | 0:c92be90656b7 | 10 | _PinA = 0; |
kaushalpkk | 0:c92be90656b7 | 11 | _PinB = 0; |
kaushalpkk | 0:c92be90656b7 | 12 | } |
kaushalpkk | 0:c92be90656b7 | 13 | |
kaushalpkk | 0:c92be90656b7 | 14 | void DCMotor::driveIt(float perCent) { |
kaushalpkk | 0:c92be90656b7 | 15 | if (perCent > 0) { |
kaushalpkk | 0:c92be90656b7 | 16 | _PinA = 0; |
kaushalpkk | 0:c92be90656b7 | 17 | _PinB = 1; |
kaushalpkk | 1:88772267f757 | 18 | |
kaushalpkk | 0:c92be90656b7 | 19 | } else { |
kaushalpkk | 0:c92be90656b7 | 20 | _PinA = 1; |
kaushalpkk | 0:c92be90656b7 | 21 | _PinB = 0; |
kaushalpkk | 0:c92be90656b7 | 22 | } |
kaushalpkk | 1:88772267f757 | 23 | _PWMPin = fabs(perCent/100); |
kaushalpkk | 0:c92be90656b7 | 24 | } |