Small class to control a stepper motor
Motor.cpp@0:278f07b2be46, 2012-11-25 (annotated)
- Committer:
- melangeaddict
- Date:
- Sun Nov 25 23:10:31 2012 +0000
- Revision:
- 0:278f07b2be46
[mbed] converted /tuner/Motor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
melangeaddict | 0:278f07b2be46 | 1 | #include "Motor.h" |
melangeaddict | 0:278f07b2be46 | 2 | |
melangeaddict | 0:278f07b2be46 | 3 | Motor::Motor(PinName enable,PinName direction,PinName step) : _enable(enable), _direction(direction), _step(step) { |
melangeaddict | 0:278f07b2be46 | 4 | _enable=1; |
melangeaddict | 0:278f07b2be46 | 5 | } |
melangeaddict | 0:278f07b2be46 | 6 | |
melangeaddict | 0:278f07b2be46 | 7 | Motor::~Motor() { |
melangeaddict | 0:278f07b2be46 | 8 | } |
melangeaddict | 0:278f07b2be46 | 9 | |
melangeaddict | 0:278f07b2be46 | 10 | void Motor::motor_turn(int direction, int steps) { |
melangeaddict | 0:278f07b2be46 | 11 | _enable=0; |
melangeaddict | 0:278f07b2be46 | 12 | float freq=600;//frequency of PWM signal to drive stepper motor |
melangeaddict | 0:278f07b2be46 | 13 | _step.period(1/freq); |
melangeaddict | 0:278f07b2be46 | 14 | _step.write(.5); |
melangeaddict | 0:278f07b2be46 | 15 | _direction=direction; |
melangeaddict | 0:278f07b2be46 | 16 | wait(steps*(1/freq)); |
melangeaddict | 0:278f07b2be46 | 17 | _step.write(0); |
melangeaddict | 0:278f07b2be46 | 18 | _enable=1; |
melangeaddict | 0:278f07b2be46 | 19 | } |