Guest User

Untitled

a guest
Dec 23rd, 2020
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <Servo.h>
  2. const int switchPin = 8; //active low
  3. const int servoPin = 9;
  4. const int blade_home = 90;
  5. const int blade_cut = 145;
  6. Servo servo;
  7.  
  8. void setup() {
  9. pinMode(switchPin, HIGH);
  10. servo.attach(servoPin); // connect to servo
  11. servo.write(blade_home); // move blade to open position
  12. delay(1000); // wait for servo to complete movement
  13. servo.detach(); // disconnect from servo
  14. }
  15.  
  16. void loop() {
  17. if (digitalRead(switchPin)) // when button is depressed upon filament insertion
  18. { delay(500); // wait for filament insertion to complete
  19. servo.attach(servoPin); // connect to servo
  20. servo.write(blade_cut); // move blade to cut position
  21. delay(1000); // wait for servo to complete movement
  22. servo.write(blade_home); // move blade to home position
  23. delay(2500); // wait for servo to complete movement
  24. servo.detach(); // disconnect from servo
  25. }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment