Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. int Pin1 = 8;//IN1 is connected to 10
  2. int Pin2 = 9;//IN2 is connected to 11
  3. int Pin3 = 10;//IN3 is connected to 12
  4. int Pin4 = 11;//IN4 is connected to 13
  5. int switchCW =2;//define input pin for CW push button
  6. int switchStop=3;//define input pin for Stop push button
  7. int switchCCW =4;//define input pin for CCW push button
  8.  
  9. int pole1[] ={0,0,0,0, 0,1,1,1, 0};//pole1, 8 step values
  10. int pole2[] ={0,0,0,1, 1,1,0,0, 0};//pole2, 8 step values
  11. int pole3[] ={0,1,1,1, 0,0,0,0, 0};//pole3, 8 step values
  12. int pole4[] ={1,1,0,0, 0,0,0,1, 0};//pole4, 8 step values
  13.  
  14.  
  15.  
  16. int poleStep = 0;
  17. int dirStatus = 3;// stores direction status 3= stop (do not change)
  18.  
  19. void setup()
  20. {
  21. pinMode(Pin1, OUTPUT);//define pin for ULN2003 in1
  22. pinMode(Pin2, OUTPUT);//define pin for ULN2003 in2
  23. pinMode(Pin3, OUTPUT);//define pin for ULN2003 in3
  24. pinMode(Pin4, OUTPUT);//define pin for ULN2003 in4
  25.  
  26. pinMode(switchCW,INPUT_PULLUP);// CW push button pin as input
  27. pinMode(switchStop,INPUT_PULLUP);//Stop push button pin as input
  28. pinMode(switchCCW,INPUT_PULLUP);//CCW push button pin as input
  29.  
  30. }
  31. void loop()
  32. {
  33.  
  34. if(digitalRead(switchCCW) == HIGH)
  35. {
  36. dirStatus =1;
  37. }else if(digitalRead(switchCW) == HIGH)
  38. {
  39. dirStatus = 2;
  40. }else if(digitalRead(switchStop) == HIGH)
  41. {
  42. dirStatus =3;
  43. }
  44. if(dirStatus ==1){
  45. poleStep++;
  46. driveStepper(poleStep);
  47. }else if(dirStatus ==2){
  48. poleStep--;
  49. driveStepper(poleStep);
  50. }else{
  51. driveStepper(8);
  52. }
  53. if(poleStep>7){
  54. poleStep=0;
  55. }
  56. if(poleStep<0){
  57. poleStep=7;
  58. }
  59. delay(1);
  60.  
  61. }// loop
  62.  
  63.  
  64.  
  65. /*
  66. * @brief sends signal to the motor
  67. * @param "c" is integer representing the pol of motor
  68. * @return does not return anything
  69. *
  70. * www.Robojax.com code June 2019
  71. */
  72. void driveStepper(int c)
  73. {
  74. digitalWrite(Pin1, pole1[c]);
  75. digitalWrite(Pin2, pole2[c]);
  76. digitalWrite(Pin3, pole3[c]);
  77. digitalWrite(Pin4, pole4[c]);
  78. }//driveStepper end here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement