Skip to content

Instantly share code, notes, and snippets.

@ultramcu
Created June 16, 2014 14:17
Show Gist options
  • Save ultramcu/2bef889953baf188fd26 to your computer and use it in GitHub Desktop.
Save ultramcu/2bef889953baf188fd26 to your computer and use it in GitHub Desktop.
Step Motor Drive with THB7128
#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