Guest User

Untitled

a guest
Jun 14th, 2017
3,940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. int Pin2 = 2; //Pin 1 cannot be used for this. Start at 2.
  2. int Pin3 = 3;
  3. int Pin4 = 4;
  4. int Pin5 = 5;
  5. int Pin8 = 8;
  6. int Pin9 = 9;
  7.  
  8. int SliderLength = 1050; //Travel length in mm
  9. double TravelTime; //Used for calculations in the loop section.
  10. double Steps = 10695; //Steps required to move along the entire Rail.400 * (SliderLength / (3.14 * PulleyDiameter))
  11. double StepDelay;
  12. int StepsTaken = 0;
  13.  
  14. bool s2; ///s2 stands for switch2_status. It starts at 2 so we can match the pin.
  15. bool s3;
  16. bool s4;
  17. bool s5;
  18.  
  19.  
  20. const int stepPin = 8; //defines the step pin
  21. const int dirPin = 9; //defines the direction pin
  22.  
  23.  
  24. void setup()
  25. {
  26. Serial.begin(9600); //Required for Serial Monitor
  27. pinMode(Pin2, INPUT);
  28. pinMode(Pin3, INPUT);
  29. pinMode(Pin4, INPUT);
  30. pinMode(Pin5, INPUT);
  31.  
  32. pinMode(stepPin, OUTPUT);
  33. pinMode(dirPin, OUTPUT);
  34. Serial.println("");
  35. Serial.print("Steps = ");
  36. Serial.println(Steps);
  37. digitalWrite(dirPin, HIGH); //Defines the direction of travel. LOW reverses it.
  38. }
  39.  
  40. void MoveStepper()
  41. {
  42. digitalWrite(stepPin, HIGH); //This moves the stepper by 1 step.
  43. delayMicroseconds(400); //Depends on Motor 500-1000 is good
  44. digitalWrite(stepPin, LOW);
  45. delayMicroseconds(400);
  46. StepsTaken++;
  47. }
  48.  
  49. // the loop routine runs over and over again forever:
  50. void loop()
  51. {
  52. s2 = digitalRead(Pin2); ///This checks the status of the switches.
  53. s3 = digitalRead(Pin3);
  54. s4 = digitalRead(Pin4);
  55. s5 = digitalRead(Pin5);
  56.  
  57.  
  58. if ((s2 == LOW) && (s3 == HIGH) && (s4 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  59. {
  60. if (StepsTaken < Steps)
  61. { Serial.println("Mode = s2");
  62. TravelTime = 10; //The slider will move the distance in x seconds.enter 5
  63. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  64. MoveStepper();
  65. Serial.print("Stepdelay = ");
  66. Serial.println(StepDelay);
  67. delay (StepDelay);
  68. // THis is in miliseconds (ms) Not MICRO!
  69.  
  70. }
  71. }
  72.  
  73.  
  74. if ((s3 == LOW) && (s2 == HIGH) && (s4 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  75. {
  76. if (StepsTaken < Steps)
  77. { Serial.println("Mode = s3");
  78. TravelTime = 20; //The slider will move the distance in x seconds.enter 5
  79. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  80. MoveStepper();
  81. Serial.print("Stepdelay = ");
  82. Serial.println(StepDelay);
  83. delay (StepDelay);
  84. // THis is in miliseconds (ms) Not MICRO!
  85.  
  86. }
  87. }
  88. if ((s4 == LOW) && (s2 == HIGH) && (s3 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  89. {
  90. if (StepsTaken < Steps)
  91. { Serial.println("Mode = s4");
  92. TravelTime = 30; //The slider will move the distance in x seconds.enter 5
  93. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  94. MoveStepper();
  95. Serial.print("Stepdelay = ");
  96. Serial.println(StepDelay);
  97. delay (StepDelay);
  98. // THis is in miliseconds (ms) Not MICRO!
  99.  
  100. }
  101. }
  102. if ((s5 == LOW) && (s2 == HIGH) && (s3 == HIGH) && (s4 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  103. {
  104. if (StepsTaken < Steps)
  105. { Serial.println("Mode = s5");
  106. TravelTime = 60; //The slider will move the distance in x seconds.enter 5
  107. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  108. MoveStepper();
  109. Serial.print("Stepdelay = ");
  110. Serial.println(StepDelay);
  111. delay (StepDelay);
  112. // THis is in miliseconds (ms) Not MICRO!
  113.  
  114. }
  115. }
  116. if ((s2 == LOW) && (s3 == LOW) && (s4 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  117. {
  118. if (StepsTaken < Steps)
  119. { Serial.println("Mode = s2,3");
  120. TravelTime = 120; //The slider will move the distance in x seconds.enter 5
  121. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  122. MoveStepper();
  123. Serial.print("Stepdelay = ");
  124. Serial.println(StepDelay);
  125. delay (StepDelay);
  126. // THis is in miliseconds (ms) Not MICRO!
  127.  
  128. }
  129. }
  130. if ((s2 == LOW) && (s4 == LOW) && (s3 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  131. {
  132. if (StepsTaken < Steps)
  133. { Serial.println("Mode = s2,4");
  134. TravelTime = 300; //The slider will move the distance in x seconds.enter 5
  135. StepDelay = ((TravelTime / Steps) - 0.0008)*1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  136. MoveStepper();
  137. Serial.print("Stepdelay = ");
  138. Serial.println(StepDelay);
  139. delay (StepDelay);
  140. // THis is in miliseconds (ms) Not MICRO!
  141.  
  142. }
  143.  
  144. }
  145. if ((s2 == LOW) && (s5 == LOW) && (s3 == HIGH) && (s4 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  146. {
  147. if (StepsTaken < Steps)
  148. { Serial.println("Mode = s2,5");
  149. TravelTime = 1200; //The slider will move the distance in 30s
  150. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  151. MoveStepper();
  152. Serial.print("Stepdelay = ");
  153. Serial.println(StepDelay);
  154. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  155. }
  156.  
  157. }
  158. if ((s3 == LOW) && (s4 == LOW) && (s2 == HIGH) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  159. {
  160. if (StepsTaken < Steps)
  161. { Serial.println("Mode = s3,4");
  162. TravelTime = 1800; //The slider will move the distance in 30s
  163. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  164. MoveStepper();
  165. Serial.print("Stepdelay = ");
  166. Serial.println(StepDelay);
  167. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  168. }
  169.  
  170. }
  171. if ((s3 == LOW) && (s5 == LOW) && (s2 == HIGH) && (s4 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  172. {
  173. if (StepsTaken < Steps)
  174. { Serial.println("Mode = s3,5");
  175. TravelTime = 2400; //The slider will move the distance in 30s
  176. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  177. MoveStepper();
  178. Serial.print("Stepdelay = ");
  179. Serial.println(StepDelay);
  180. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  181. }
  182.  
  183. }
  184. if ((s4 == LOW) && (s5 == LOW) && (s2 == HIGH) && (s3 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  185. {
  186. if (StepsTaken < Steps)
  187. { Serial.println("Mode = s4,5");
  188. TravelTime = 3000; //The slider will move the distance in 30s
  189. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  190. MoveStepper();
  191. Serial.print("Stepdelay = ");
  192. Serial.println(StepDelay);
  193. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  194. }
  195.  
  196. }
  197. if ((s2 == LOW) && (s3 == LOW) && (s4 == LOW) && (s5 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  198. {
  199. if (StepsTaken < Steps)
  200. { Serial.println("Mode = s2,3,4");
  201. TravelTime = 3600; //The slider will move the distance in 30s
  202. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  203. MoveStepper();
  204. Serial.print("Stepdelay = ");
  205. Serial.println(StepDelay);
  206. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  207. }
  208.  
  209. }
  210. if ((s5 == LOW) && (s3 == LOW) && (s4 == LOW) && (s2 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  211. {
  212. if (StepsTaken < Steps)
  213. { Serial.println("Mode = s3,4,5");
  214. TravelTime = 5400; //The slider will move the distance in 30s
  215. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  216. MoveStepper();
  217. Serial.print("Stepdelay = ");
  218. Serial.println(StepDelay);
  219. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  220. }
  221.  
  222. }
  223. if ((s2 == LOW) && (s5 == LOW) && (s4 == LOW) && (s3 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  224. {
  225. if (StepsTaken < Steps)
  226. { Serial.println("Mode = s2,4,5");
  227. TravelTime = 14400; //The slider will move the distance in 30s
  228. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  229. MoveStepper();
  230. Serial.print("Stepdelay = ");
  231. Serial.println(StepDelay);
  232. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  233. }
  234.  
  235. }
  236. if ((s2 == LOW) && (s3 == LOW) && (s5 == LOW) && (s4 == HIGH)) ///LOW means switch is pressed/closed/conductive.
  237. {
  238. if (StepsTaken < Steps)
  239. { Serial.println("Mode = s2,3,5");
  240. TravelTime = 28800; //The slider will move the distance in 30s
  241. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  242. MoveStepper();
  243. Serial.print("Stepdelay = ");
  244. Serial.println(StepDelay);
  245. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  246. }
  247.  
  248. }
  249. if ((s2 == LOW) && (s3 == LOW) && (s4 == LOW) & (s5 == LOW)) ///LOW means switch is pressed/closed/conductive.
  250. {
  251. if (StepsTaken < Steps)
  252. { Serial.println("Mode = s2,3,4,5");
  253. TravelTime = 10; //The slider will move the distance in 30s
  254. StepDelay = ((TravelTime / Steps) - 0.002) * 1000; //This calculates the delay required in ms between steps to make the journey in the desired amount of time. 0.001 Seconds are deducted because the MoveStepper Method includes 2x 500microseconds delays.
  255. MoveStepper();
  256. Serial.print("Stepdelay = ");
  257. Serial.println(StepDelay);
  258. delay (StepDelay); // THis is in miliseconds (ms) Not MICRO!
  259. }
  260.  
  261. }
  262. }
Add Comment
Please, Sign In to add comment