Adam Resnick / StepperMotors

Dependents:   CNCAirbrushCode

Committer:
stretch
Date:
Sat Apr 28 21:08:58 2012 +0000
Revision:
0:3058939fa37c
Initial Public Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stretch 0:3058939fa37c 1 #include "Stepper.h"
stretch 0:3058939fa37c 2
stretch 0:3058939fa37c 3 Stepper::Stepper(PinName step, PinName dir, PinName en) : _step(step), _dir(dir), _en(en) {
stretch 0:3058939fa37c 4 _step = 0, _dir = 0, _en = 1;
stretch 0:3058939fa37c 5 _position = 0;
stretch 0:3058939fa37c 6 }
stretch 0:3058939fa37c 7
stretch 0:3058939fa37c 8 void Stepper::stepOn(bool direction) {
stretch 0:3058939fa37c 9 _dir = direction;
stretch 0:3058939fa37c 10 if (direction) {
stretch 0:3058939fa37c 11 _position++;
stretch 0:3058939fa37c 12 } else {
stretch 0:3058939fa37c 13 _position--;
stretch 0:3058939fa37c 14 }
stretch 0:3058939fa37c 15 _step = 1;
stretch 0:3058939fa37c 16 }
stretch 0:3058939fa37c 17
stretch 0:3058939fa37c 18 void Stepper::stepOff(void) {
stretch 0:3058939fa37c 19 _step = 0;
stretch 0:3058939fa37c 20 }
stretch 0:3058939fa37c 21
stretch 0:3058939fa37c 22 void Stepper::enable(bool en) {
stretch 0:3058939fa37c 23 _en = !en;
stretch 0:3058939fa37c 24 }
stretch 0:3058939fa37c 25
stretch 0:3058939fa37c 26 void Stepper::setPosition(long position) {
stretch 0:3058939fa37c 27 _position = position;
stretch 0:3058939fa37c 28 }
stretch 0:3058939fa37c 29
stretch 0:3058939fa37c 30 long Stepper::getPosition(void) {
stretch 0:3058939fa37c 31 return _position;
stretch 0:3058939fa37c 32 }