Guest User

Untitled

a guest
Aug 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. // purple is step wire
  2. // white is direction wire
  3.  
  4. #define xStepPin 2
  5. #define xDirPin 3
  6. #define yStepPin 4
  7. #define yDirPin 5
  8. #define zStepPin 6
  9. #define zDirPin 7
  10. #define limitSenseA 32
  11. #define limitSenseB 34
  12.  
  13. #define zNegBut 52
  14. #define zPosBut 50
  15. #define yNegBut 48
  16. #define yPosBut 46
  17. #define xNegBut 44
  18. #define xPosBut 42
  19.  
  20. #define holdBut 40
  21. #define eStop 38
  22. #define emptyPin 36
  23.  
  24. #define relayPin1 8
  25. #define relayPin2 9
  26. #define relayPin3 10
  27. #define relayPin4 11
  28.  
  29. void setup() {
  30. pinMode(xStepPin, OUTPUT);
  31. pinMode(xDirPin, OUTPUT);
  32. pinMode(yStepPin, OUTPUT);
  33. pinMode(yDirPin, OUTPUT);
  34. pinMode(zStepPin, OUTPUT);
  35. pinMode(zDirPin, OUTPUT);
  36.  
  37. pinMode(limitSenseA, INPUT);
  38. pinMode(limitSenseB, OUTPUT);
  39.  
  40. pinMode(zNegBut, INPUT_PULLUP);
  41. pinMode(zPosBut, INPUT_PULLUP);
  42. pinMode(yNegBut, INPUT_PULLUP);
  43. pinMode(yPosBut, INPUT_PULLUP);
  44. pinMode(xNegBut, INPUT_PULLUP);
  45. pinMode(xPosBut, INPUT_PULLUP);
  46.  
  47. pinMode(holdBut, INPUT_PULLUP);
  48. pinMode(eStop, INPUT_PULLUP);
  49.  
  50. pinMode(relayPin1, OUTPUT);
  51. pinMode(relayPin2, OUTPUT);
  52. pinMode(relayPin3, OUTPUT);
  53. pinMode(relayPin4, OUTPUT);
  54.  
  55. Serial.begin(9600);
  56.  
  57. resetRelays();
  58. }
  59.  
  60. void loop() {
  61. //reportButtons();
  62. digitalWrite(relayPin1, HIGH);
  63. delay(1000);
  64. digitalWrite(relayPin1, LOW);
  65. delay(1000);
  66. }
  67.  
  68. void resetRelays() {
  69. digitalWrite(relayPin1, HIGH);
  70. digitalWrite(relayPin2, HIGH);
  71. digitalWrite(relayPin3, HIGH);
  72. digitalWrite(relayPin4, HIGH);
  73. }
  74.  
  75. int reportButtons() {
  76. String out = "";
  77. out = out + "Z-:" + digitalRead(zNegBut) + ", ";
  78. out = out + "Z+:" + digitalRead(zPosBut) + ", ";
  79. out = out + "Y-:" + digitalRead(yNegBut) + ", ";
  80. out = out + "Y+:" + digitalRead(yPosBut) + ", ";
  81. out = out + "X-:" + digitalRead(xNegBut) + ", ";
  82. out = out + "X+:" + digitalRead(xPosBut) + ", ";
  83. out = out + "H:" + digitalRead(holdBut) + ", ";
  84. out = out + "E:" + digitalRead(eStop);
  85. return Serial.println(out);
  86. }
  87.  
  88. void stepTest() {
  89. digitalWrite(xDirPin, HIGH);
  90.  
  91. for (int x = 0; x < 200; x++) {
  92. digitalWrite(xStepPin, HIGH);
  93. delayMicroseconds(500);
  94. digitalWrite(xStepPin, LOW);
  95. delayMicroseconds(500);
  96. }
  97. delay(250);
  98.  
  99. digitalWrite(xDirPin, LOW);
  100.  
  101. for (int x = 0; x < 200; x++) {
  102. digitalWrite(xStepPin, HIGH);
  103. delayMicroseconds(500);
  104. digitalWrite(xStepPin, LOW);
  105. delayMicroseconds(500);
  106. }
  107. delay(1000);
  108.  
  109. digitalWrite(yDirPin, HIGH);
  110.  
  111. for (int x = 0; x < 200; x++) {
  112. digitalWrite(yStepPin, HIGH);
  113. delayMicroseconds(500);
  114. digitalWrite(yStepPin, LOW);
  115. delayMicroseconds(500);
  116. }
  117. delay(250);
  118.  
  119. digitalWrite(yDirPin, LOW);
  120.  
  121. for (int x = 0; x < 200; x++) {
  122. digitalWrite(yStepPin, HIGH);
  123. delayMicroseconds(500);
  124. digitalWrite(yStepPin, LOW);
  125. delayMicroseconds(500);
  126. }
  127. delay(1000);
  128.  
  129. digitalWrite(zDirPin, HIGH);
  130.  
  131. for (int x = 0; x < 200; x++) {
  132. digitalWrite(zStepPin, HIGH);
  133. delayMicroseconds(500);
  134. digitalWrite(zStepPin, LOW);
  135. delayMicroseconds(500);
  136. }
  137. delay(250);
  138.  
  139. digitalWrite(zDirPin, LOW);
  140.  
  141. for (int x = 0; x < 200; x++) {
  142. digitalWrite(zStepPin, HIGH);
  143. delayMicroseconds(500);
  144. digitalWrite(zStepPin, LOW);
  145. delayMicroseconds(500);
  146. }
  147. delay(1000);
  148. }
  149.  
  150. void jog() {
  151. if (digitalRead(xPosBut)) {
  152. xMotor(true, 2);
  153. }
  154.  
  155. if (digitalRead(xNegBut)) {
  156. xMotor(false, 2);
  157. }
  158.  
  159. if (digitalRead(yPosBut)) {
  160. yMotor(true, 2);
  161. }
  162.  
  163. if (digitalRead(yNegBut)) {
  164. yMotor(false, 2);
  165. }
  166.  
  167. if (digitalRead(zPosBut)) {
  168. zMotor(true, 2);
  169. }
  170.  
  171. if (digitalRead(zNegBut)) {
  172. zMotor(false, 2);
  173. }
  174. }
  175.  
  176. void xMotor(bool dir, int dist) {
  177. if (dir) {
  178. digitalWrite(xDirPin, HIGH);
  179. } else {
  180. digitalWrite(xDirPin, LOW);
  181. }
  182.  
  183. for (int x = 0; x < dist; x++) {
  184. digitalWrite(xStepPin, HIGH);
  185. delayMicroseconds(500);
  186. digitalWrite(xStepPin, LOW);
  187. delayMicroseconds(500);
  188. }
  189. }
  190.  
  191. void yMotor(bool dir, int dist) {
  192. if (dir) {
  193. digitalWrite(yDirPin, HIGH);
  194. } else {
  195. digitalWrite(yDirPin, LOW);
  196. }
  197.  
  198. for (int x = 0; x < dist; x++) {
  199. digitalWrite(yStepPin, HIGH);
  200. delayMicroseconds(500);
  201. digitalWrite(yStepPin, LOW);
  202. delayMicroseconds(500);
  203. }
  204. }
  205.  
  206. void zMotor(bool dir, int dist) {
  207. if (dir) {
  208. digitalWrite(zDirPin, HIGH);
  209. } else {
  210. digitalWrite(zDirPin, LOW);
  211. }
  212.  
  213. for (int x = 0; x < dist; x++) {
  214. digitalWrite(zStepPin, HIGH);
  215. delayMicroseconds(500);
  216. digitalWrite(zStepPin, LOW);
  217. delayMicroseconds(500);
  218. }
  219. }
Add Comment
Please, Sign In to add comment