Created
June 16, 2014 14:17
-
-
Save ultramcu/2bef889953baf188fd26 to your computer and use it in GitHub Desktop.
Step Motor Drive with THB7128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Makeblock.h> | |
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <Wire.h> | |
#include <AccelStepper.h> | |
#define _PIN_CLK_ 13 | |
#define _PIN_CW_ 12 | |
#define _DIP_SW_EXCITATION_ 16 | |
#define _MOTOR_NUMER_OF_STEP_PER_ROUND_ 200 | |
#define _SW_MAX_SETEP_ (_DIP_SW_EXCITATION_ * _MOTOR_NUMER_OF_STEP_PER_ROUND_) | |
AccelStepper stepper(AccelStepper::DRIVER, _PIN_CLK_, _PIN_CW_); | |
long current_position; | |
void setup() | |
{ | |
stepper.setAcceleration(100000); | |
stepper.setCurrentPosition(0); | |
stepper.setMaxSpeed(_DIP_SW_EXCITATION_ * 20); | |
} | |
void loop() | |
{ | |
current_position = stepper.currentPosition(); | |
if(current_position >= _SW_MAX_SETEP_) | |
{ | |
stepper.moveTo(0); | |
} | |
if(current_position <= 0) | |
{ | |
stepper.moveTo(_SW_MAX_SETEP_); | |
} | |
stepper.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment