Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. // Motor x-Axis
  2. int Red = 14; // Firing order for 4-Wire Micro-step Motor
  3. int Brown = 15; // First Brown coil
  4. int Yellow = 16; // Then Yellow coil and so on...
  5. int Orange = 10;
  6. // Motor y-axis
  7. // int Red = 2; // Firing order for 28BYJ-48 Stepper Motor
  8. // int Brown = 3; // First Brown coil
  9. // int Yellow = 4; // Then Yellow coil and so on...
  10. // int Orange = 5;
  11.  
  12. long del = 500000; // 50.000 (+SPEED) -> 999.000 (-SPEED)// ABOVE this figure the motor will stall:/
  13.  
  14. void setup() {
  15. pinMode(Red, OUTPUT);
  16. pinMode(Brown, OUTPUT);
  17. pinMode(Yellow, OUTPUT);
  18. pinMode(Orange, OUTPUT);
  19.  
  20. for (int e = 0; e <= 5; e++) {
  21. //for (int i = 0; i <= 40; i++) {
  22. for (int i = 0; i <= 35; i++) {
  23. phaseOne();
  24. phaseTwo();
  25. phaseThree();
  26. phaseFour();
  27. }
  28. //for (int j = 0; j <= 40; j++) {
  29. for (int j = 0; j <= 35; j++) {
  30. phaseFour();
  31. phaseThree();
  32. phaseTwo();
  33. phaseOne();
  34.  
  35. }
  36. }
  37. }
  38.  
  39. void phaseOne() {
  40. digitalWrite(Red, LOW);
  41. digitalWrite(Brown, HIGH);
  42. digitalWrite(Yellow, HIGH);
  43. digitalWrite(Orange, LOW);
  44. delayMicroseconds(del);
  45. }
  46. void phaseTwo() {
  47. digitalWrite(Red, LOW);
  48. digitalWrite(Brown, HIGH);
  49. digitalWrite(Yellow, LOW);
  50. digitalWrite(Orange, HIGH);
  51. delayMicroseconds(del);
  52. }
  53. void phaseThree() {
  54. digitalWrite(Red, HIGH);
  55. digitalWrite(Brown, LOW);
  56. digitalWrite(Yellow, LOW);
  57. digitalWrite(Orange, HIGH);
  58. delayMicroseconds(del);
  59. }
  60. void phaseFour() {
  61. digitalWrite(Red, HIGH);
  62. digitalWrite(Brown, LOW);
  63. digitalWrite(Yellow, HIGH);
  64. digitalWrite(Orange, LOW);
  65. delayMicroseconds(del);
  66. }
  67. void motorOff() {
  68. digitalWrite(Red, LOW);
  69. digitalWrite(Brown, LOW);
  70. digitalWrite(Yellow, LOW);
  71. digitalWrite(Orange, LOW);
  72. }
  73.  
  74. // the loop routine runs over and over again forever:
  75. void loop() {
  76. for (int e = 0; e <= 5; e++) {
  77. //for (int i = 0; i <= 40; i++) {
  78. for (int i = 0; i <= 35; i++) {
  79. phaseOne();
  80. phaseTwo();
  81. phaseThree();
  82. phaseFour();
  83. }
  84. //for (int j = 0; j <= 40; j++) {
  85. for (int j = 0; j <= 35; j++) {
  86. phaseFour();
  87. phaseThree();
  88. phaseTwo();
  89. phaseOne();
  90.  
  91. }
  92. }
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement