Small class to control a stepper motor

Dependents:   tuner

Files at this revision

API Documentation at this revision

Comitter:
melangeaddict
Date:
Sun Nov 25 23:10:31 2012 +0000
Commit message:
[mbed] converted /tuner/Motor

Changed in this revision

Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Motor.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Sun Nov 25 23:10:31 2012 +0000
@@ -0,0 +1,19 @@
+#include "Motor.h"
+
+Motor::Motor(PinName enable,PinName direction,PinName step) : _enable(enable), _direction(direction), _step(step) {
+_enable=1;
+}
+
+Motor::~Motor() {
+}
+
+void Motor::motor_turn(int direction, int steps) {
+    _enable=0;
+    float freq=600;//frequency of PWM signal to drive stepper motor
+    _step.period(1/freq);
+    _step.write(.5);
+    _direction=direction;
+    wait(steps*(1/freq));
+    _step.write(0);
+    _enable=1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h	Sun Nov 25 23:10:31 2012 +0000
@@ -0,0 +1,20 @@
+#pragma once
+#include "mbed.h"
+#include "string.h"
+
+using namespace std;
+
+class Motor {
+
+public:
+
+    Motor(PinName enable,PinName direction,PinName step);
+    ~Motor();
+
+    void motor_turn(int, int);
+
+private:
+    DigitalOut _enable;
+    DigitalOut _direction;
+    PwmOut _step;
+};
\ No newline at end of file