manhoosbilli1

servo all

Jul 12th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo claw;
  3. Servo pivot;
  4. Servo upperPivot;
  5. Servo clawRotator;
  6. Servo base;
  7. int clawPos;
  8.  
  9.  
  10. bool goingToDefaultFlag;
  11. bool goingToObjectFlag;
  12. bool goingToSpecificFlag;
  13.  
  14. const int minimumPivot = 180;
  15. const int minimumUpperPivot;
  16. const int maximumPivot = 120;
  17. const int maximumUpperPivot;
  18. const int basedelay;
  19. const int openClaw = 160;
  20. const int closeClaw = 103;
  21. int defaultUpperPivot;
  22. const int verticalClawRot = 180;
  23. const int horizontalClawRot =90;
  24.  
  25. bool trigger;
  26. void setup() {
  27. pivot.attach(3);
  28. claw.attach(10);
  29. clawRotator.attach(9);
  30. upperPivot.attach(5);
  31. base.attach(6);
  32.  
  33.  
  34.  
  35. }
  36. enum state{Default, pickObject, dropObject};
  37. int currentState = Default;
  38. void loop() {
  39. pivot.write(180);
  40. delay(2000);
  41. pivot.write(120);
  42.  
  43. }
  44.  
  45.  
  46. void DefaultFunction() {
  47. base.write(90); //stop base
  48. pivot.write(180); //extends fully
  49. delay(1000);
  50. upperPivot.write(0); //find out its medium extreme and minimum
  51. delay(1000);
  52. clawRotator.write(0); //find out its vertical and horizontal
  53. delay(1000);
  54. claw.write(0);
  55. }
  56.  
  57. void armFunction(){
  58. //if trigger true;
  59. switch(currentState) {
  60. case Default:
  61. //arm goes to default.. waits for signal
  62. DefaultFunction();
  63. //if(trigger == true) {
  64. //pickObect
  65.  
  66. break;
  67.  
  68. case pickObject:
  69. //signal recieved, goes to pick object
  70. base.write(0); //travel left for until u get to 90*
  71. delay(9);
  72. base.write(90); //stop base
  73. delay(500); //this needs to be slow to look pretty
  74. pivot.write(minimumPivot);
  75. upperPivot.write(defaultUpperPivot);
  76. clawRotator.write(0);
  77. claw.write(0);
  78. break;
  79.  
  80. case dropObject:
  81. //object picked..going to drop
  82. //goes to default mode();
  83. break;
  84.  
  85. }
  86. }
Add Comment
Please, Sign In to add comment