Advertisement
Guest User

44444444444444444444444444444444444444

a guest
Jan 22nd, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. // NuMechRon design by Victorrr161 https://www.thingiverse.com/thing:2381829
  2. // Conversion for Arduino Nano and stepperboard ULN2003A by Jeroen Jonkman, 30/12/2017
  3.  
  4. // Wiring:
  5. // Connect pin GND of the Arduino to pin GND of the stepper board
  6. // Connect pin 5V of the Arduino to pin VCC of the stepper board
  7. #define OUT1 A1 // Connect pin A1 of the Arduino to pin IN4 of the stepper board
  8. #define OUT2 A2 // Connect pin A2 of the Arduino to pin IN3 of the stepper board
  9. #define OUT3 A3 // Connect pin A3 of the Arduino to pin IN2 of the stepper board
  10. #define OUT4 A4 // Connect pin A4 of the Arduino to pin IN1 of the stepper board
  11.  
  12. int countStep = 0; // Initialize countStep
  13.  
  14. void setup() // Handle setup
  15. {
  16. pinMode(OUT1, OUTPUT); // Use A1 as a digital output
  17. pinMode(OUT2, OUTPUT); // Use A2 as a digital output
  18. pinMode(OUT3, OUTPUT); // Use A3 as a digital output
  19. pinMode(OUT4, OUTPUT); // Use A4 as a digital output
  20. }
  21.  
  22. void loop() // Handle loop
  23. {
  24. stepping(); // Call stepping
  25. delayMicroseconds(30943); // Pause loop, use value of 30943 for timekeeping or 1000 for testing at high speed
  26. }
  27.  
  28. void stepping() // Handle stepping
  29. {
  30. switch(countStep) // Handle each step of countStep
  31. {
  32. case 0:
  33. digitalWrite(OUT1, LOW);
  34. digitalWrite(OUT2, LOW);
  35. digitalWrite(OUT3, HIGH);
  36. digitalWrite(OUT4, HIGH);
  37. break;
  38. case 1:
  39. digitalWrite(OUT1, LOW);
  40. digitalWrite(OUT2, LOW);
  41. digitalWrite(OUT3, HIGH);
  42. digitalWrite(OUT4, LOW);
  43. break;
  44. case 2:
  45. digitalWrite(OUT1, LOW);
  46. digitalWrite(OUT2, HIGH);
  47. digitalWrite(OUT3, HIGH);
  48. digitalWrite(OUT4, LOW);
  49. break;
  50. case 3:
  51. digitalWrite(OUT1, LOW);
  52. digitalWrite(OUT2, HIGH);
  53. digitalWrite(OUT3, LOW);
  54. digitalWrite(OUT4, LOW);
  55. break;
  56. case 4:
  57. digitalWrite(OUT1, HIGH);
  58. digitalWrite(OUT2, HIGH);
  59. digitalWrite(OUT3, LOW);
  60. digitalWrite(OUT4, LOW);
  61. break;
  62. case 5:
  63. digitalWrite(OUT1, HIGH);
  64. digitalWrite(OUT2, LOW);
  65. digitalWrite(OUT3, LOW);
  66. digitalWrite(OUT4, LOW);
  67. break;
  68. case 6:
  69. digitalWrite(OUT1, HIGH);
  70. digitalWrite(OUT2, LOW);
  71. digitalWrite(OUT3, LOW);
  72. digitalWrite(OUT4, HIGH);
  73. break;
  74. case 7:
  75. digitalWrite(OUT1, LOW);
  76. digitalWrite(OUT2, LOW);
  77. digitalWrite(OUT3, LOW);
  78. digitalWrite(OUT4, HIGH);
  79. break;
  80. default:
  81. digitalWrite(OUT1, LOW);
  82. digitalWrite(OUT2, LOW);
  83. digitalWrite(OUT3, LOW);
  84. digitalWrite(OUT4, LOW);
  85. break;
  86. }
  87.  
  88. countStep=countStep+1; // After each cycle add 1 to countStep
  89. if(countStep==8)
  90. {countStep=0;} // Reset countStep on rollover
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement