Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Motor {
- private:
- int steps_per_revolution = 200 * 32;
- int DIR, STEP;
- int Frecventa, Cantitate = 4;
- boolean running = false, inAction = false, CW = true;
- long steps_per_pull = steps_per_revolution / Cantitate;//60 000 000 microsecunde = 1 min;
- long dela = ((60000000 / Frecventa) / 2) / steps_per_pull;
- long current_stage = 0;
- public:
- void setup(int DIR_, int STEP_) {
- DIR = DIR_;
- STEP = STEP_;
- pinMode(DIR, OUTPUT);
- pinMode(STEP, OUTPUT);
- digitalWrite(DIR, HIGH);
- }
- void toggle(int frecventa) {
- Frecventa = frecventa;
- running = !running;
- }
- boolean isInAction() {
- return inAction;
- }
- // Metoda care se apeleaza o singura data in functia loop();
- void loop() {
- Serial.println(running);
- Serial.println(inAction);
- if (running || inAction) {
- if (!inAction) {
- inAction = true;
- }
- if (CW) {
- if (++current_stage > steps_per_pull) {
- CW = false;
- digitalWrite(DIR, LOW);
- }
- } else {
- if (--current_stage < 0) {
- CW = true;
- digitalWrite(DIR, HIGH);
- inAction = false;
- }
- }
- digitalWrite(STEP, HIGH);
- delayMicroseconds(dela);
- digitalWrite(STEP, LOW);
- delayMicroseconds(dela);
- }
- }
- };
- Motor motor;
Add Comment
Please, Sign In to add comment