Advertisement
DrMDGG

cc2000

Apr 13th, 2021
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <Stepper.h>
  2. #include <Servo.h>
  3.  
  4. int stepsPerRevolution=2048;
  5. int stepsPerRevolution2=2048;
  6. Stepper myStepper(stepsPerRevolution, 8,10,9,11); //delcares pins
  7. int motSpeed=50;
  8. int d1=500;
  9. int buttonPin=2;
  10. int buttonPin2=4;
  11. int buttonF;
  12. int splitButton;
  13. int splitButton2=1;
  14. int buttonB=1;
  15. int motDir=1;
  16. int buttonRead;
  17. int buttonRead2;
  18.  
  19. int servoPin=13;
  20. int servoPos=60;
  21. int d2=250;
  22. Servo myServo;
  23. void setup() {
  24. // put your setup code here, to run once:
  25. Serial.begin(9600);
  26. myStepper.setSpeed(motSpeed); //sets motor speed
  27. pinMode(buttonPin,INPUT);
  28. pinMode(buttonPin2,INPUT);
  29. digitalWrite(buttonPin2,HIGH);
  30. digitalWrite(buttonPin,HIGH); //pin hack for internal pullup resister
  31. myServo.attach(servoPin);
  32. }
  33.  
  34. void loop() {
  35. // put your main code here, to run repeatedly:
  36. buttonF=digitalRead(buttonPin);
  37. splitButton=digitalRead(buttonPin2);
  38. Serial.println(buttonF);
  39. delay(d2);
  40. Serial.println(splitButton);
  41. delay(d2);
  42.  
  43. if (buttonB==0 && buttonF==1) {
  44. if (motDir==0) {
  45. myStepper.step(stepsPerRevolution*3); //runs one full rotation
  46. motDir=1;
  47. myServo.write(8);
  48. } //how i did it
  49. else {
  50. myStepper.step(-stepsPerRevolution*3); //runs one full rotation in negative.
  51. motDir=0;
  52. myServo.write(45);
  53. }
  54. }
  55. buttonB=buttonF;
  56.  
  57.  
  58. if (splitButton==0 && splitButton2==1) {
  59. if (motDir==0) {
  60. myServo.write(45);
  61. myStepper.step(-stepsPerRevolution2+600); //runs one full rotation
  62. motDir=1;
  63. myServo.write(8);
  64.  
  65. }
  66. else {
  67. myStepper.step(stepsPerRevolution2-300); //runs one full rotation in negative.
  68. motDir=0;
  69. myServo.write(45);
  70. myServo.write(8);
  71. myServo.write(45);
  72. }
  73. }
  74. splitButton2=splitButton;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement