Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. /*
  2. UniHobbies Arduino
  3. edits by Jorik van den Bos
  4. */
  5. //this is a built-in library
  6. #include<Stepper.h>
  7. int steps=0;
  8. int cycles=0;
  9. int stepsamount=512;
  10. int cycleamount=0;
  11.  
  12. int in1Pin =12;
  13. int in2Pin =11;
  14. int in3Pin =10;
  15. int in4Pin =9;
  16.  
  17. Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
  18.  
  19. void setup()
  20. {
  21. pinMode(in1Pin, OUTPUT);
  22. pinMode(in2Pin, OUTPUT);
  23. pinMode(in3Pin, OUTPUT);
  24. pinMode(in4Pin, OUTPUT);
  25.  
  26. // this line is for Leonardo’s, it delays the serial interface
  27. // until the terminal window is opened
  28. while(!Serial);
  29. Serial.begin(9600);
  30. motor.setSpeed(40);
  31. }
  32.  
  33. void loop()
  34. {
  35. //parse the amount of cycles
  36. if(Serial.available()) cycleamount = Serial.parseInt();
  37.  
  38.  
  39. //cycleamount should not be zero, can be set with parseInt()
  40. if (cycleamount!=0)
  41. {
  42. //before the amount of cycles is reached, cycles<cyceleamount
  43. if (cycles<cycleamount)
  44. {
  45. //stepsamount should not be zero
  46. if (stepsamount!=0)
  47. {
  48. //do the steps for 1 cycle
  49. steps+=1;
  50. if (steps<stepsamount) motor.step(1); else
  51. if (steps<stepsamount*2) motor.step(-1); else /*reset step variables*/ {steps=0; cycles+=1;}
  52. }
  53. }
  54. //else reset cycle variables
  55. else {cycles=0; cycleamount=0;}
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement