Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <AMIS30543.h>
  3.  
  4. const uint8_t amisDirPin = 2;
  5. const uint8_t amisStepPin = 3;
  6. const uint8_t amisSlaveSelect = 4;
  7.  
  8. AMIS30543 stepper;
  9.  
  10. unsigned long times;
  11.  
  12. void setup()
  13. {
  14. SPI.begin();
  15. stepper.init(amisSlaveSelect);
  16.  
  17. // Give the driver some time to power up.
  18. delay(1);
  19.  
  20. // Reset the driver to its default settings.
  21. stepper.resetSettings();
  22.  
  23. // Set the current limit. You should change the number here to
  24. // an appropriate value for your particular system.
  25. stepper.setCurrentMilliamps(650);
  26.  
  27. // Set the number of microsteps that correspond to one full step.
  28. stepper.setStepMode(128);
  29.  
  30. // Enable the motor outputs.
  31. stepper.enableDriver();
  32.  
  33. Serial.begin(9600);
  34. }
  35. void loop()
  36. {
  37. digitalWrite(amisDirPin, LOW);
  38. step(100);
  39. delay(3000);
  40. }
  41. void step(long int n)
  42. {
  43. n*=128;
  44. for(int i=0; i<n; i++)
  45. {
  46. unsigned long current = 0;
  47. times = millis();
  48.  
  49. if(current - times > 10){
  50. current = millis();
  51. digitalWrite(amisStepPin, HIGH);
  52. delayMicroseconds(4);
  53. digitalWrite(amisStepPin, LOW);
  54. delayMicroseconds(4);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement