Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <AMIS30543.h>
- const uint8_t amisDirPin = 2;
- const uint8_t amisStepPin = 3;
- const uint8_t amisSlaveSelect = 4;
- AMIS30543 stepper;
- unsigned long times;
- void setup()
- {
- SPI.begin();
- stepper.init(amisSlaveSelect);
- // Give the driver some time to power up.
- delay(1);
- // Reset the driver to its default settings.
- stepper.resetSettings();
- // Set the current limit. You should change the number here to
- // an appropriate value for your particular system.
- stepper.setCurrentMilliamps(650);
- // Set the number of microsteps that correspond to one full step.
- stepper.setStepMode(128);
- // Enable the motor outputs.
- stepper.enableDriver();
- Serial.begin(9600);
- }
- void loop()
- {
- digitalWrite(amisDirPin, LOW);
- step(100);
- delay(3000);
- }
- void step(long int n)
- {
- n*=128;
- for(int i=0; i<n; i++)
- {
- unsigned long current = 0;
- times = millis();
- if(current - times > 10){
- current = millis();
- digitalWrite(amisStepPin, HIGH);
- delayMicroseconds(4);
- digitalWrite(amisStepPin, LOW);
- delayMicroseconds(4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement