Skip to content

Commit d11689a

Browse files
committed
init
1 parent 847bc12 commit d11689a

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Name: step_drive.ino
3+
Author: mertwhocodes
4+
*/
5+
6+
#include<mwc_stepper.h>
7+
8+
#define EN_PIN 3
9+
#define DIR_PIN 2
10+
#define STEP_PIN 5
11+
12+
#define RPM 50
13+
#define RPM1 50
14+
15+
#define PULSE 1600
16+
17+
#define ClOCKWISE 1
18+
#define OTHERWISE 0
19+
20+
MWCSTEPPER nema23(EN_PIN, DIR_PIN, STEP_PIN);
21+
22+
void setup() {
23+
24+
nema23.init();
25+
26+
//nema23.active(DEACTIVE);
27+
}
28+
29+
void loop() {
30+
nema23.set(ClOCKWISE, RPM, PULSE);
31+
32+
for (size_t i = 0; i < 1600; i++)
33+
{
34+
nema23.run();
35+
}
36+
37+
delay(1000);
38+
39+
nema23.set(OTHERWISE, RPM1, PULSE);
40+
41+
for (size_t i = 0; i < 1600; i++)
42+
{
43+
//nema23.run();
44+
}
45+
}

mwc_stepper.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
//
3+
//
4+
5+
#include "mwc_stepper.h"
6+
7+
8+
MWCSTEPPER::MWCSTEPPER(uint8_t _enPin, uint8_t _dirPin, uint8_t _stepPin)
9+
{
10+
stepPin = _stepPin;
11+
dirPin = _dirPin;
12+
enPin = _enPin;
13+
}
14+
void MWCSTEPPER::init() {
15+
pinMode(stepPin, OUTPUT);
16+
pinMode(dirPin, OUTPUT);
17+
pinMode(enPin, OUTPUT);
18+
digitalWrite(enPin, LOW);
19+
20+
}
21+
void MWCSTEPPER::set(bool _dir, uint8_t _rpm, uint16_t _pulse) {
22+
digitalWrite(dirPin, _dir);
23+
rpm_t = 60000000 / 2 / _pulse / _rpm;
24+
25+
}
26+
void MWCSTEPPER::run(uint64_t _rpmt) {
27+
28+
digitalWrite(stepPin, HIGH);
29+
delayMicroseconds(_rpmt);
30+
digitalWrite(stepPin, LOW);
31+
delayMicroseconds(_rpmt);
32+
33+
}
34+
void MWCSTEPPER::run() {
35+
36+
digitalWrite(stepPin, HIGH);
37+
delayMicroseconds(rpm_t);
38+
digitalWrite(stepPin, LOW);
39+
delayMicroseconds(rpm_t);
40+
41+
}
42+
43+
void MWCSTEPPER::active(bool _active) {
44+
digitalWrite(enPin, _active);
45+
}

mwc_stepper.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// stepper.h
2+
3+
#ifndef _MWC_STEPPER_h
4+
#define _MWC_STEPPER_h
5+
6+
#if defined(ARDUINO) && ARDUINO >= 100
7+
#include "arduino.h"
8+
#else
9+
#include "WProgram.h"
10+
#endif
11+
12+
class MWCSTEPPER {
13+
14+
private:
15+
uint8_t enPin;
16+
uint8_t stepPin;
17+
uint8_t dirPin;
18+
uint64_t rpm_t=500;
19+
public:
20+
MWCSTEPPER(uint8_t _enPin, uint8_t _dirPin, uint8_t _stepPin);
21+
void init();
22+
void active(bool _active);
23+
void run(uint64_t _rpmt);
24+
void run();
25+
void set(bool _dir, uint8_t _rpm, uint16_t _pulse);
26+
};
27+
28+
29+
#endif

0 commit comments

Comments
 (0)