manhoosbilli1

abstract arm code

Jul 11th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. #include <Servo.h>
  3.  
  4. Servo base; // create servo object to control a servo
  5. Servo claw;
  6. Servo clawRotate;
  7. Servo pivot;
  8. Servo upperPivot;
  9.  
  10. int basePos;
  11. int clawPos;
  12. int clawRotatePos;
  13. int pivotPos;
  14. int upperPivot;
  15. int specificPos;
  16.  
  17. bool goingToDefaultFlag;
  18. bool goingToObjectFlag;
  19. bool goingToSpecificFlag;
  20.  
  21. int center = 90;
  22. int right = 180;
  23. int left = 0;
  24. int Up = 180;
  25. int UpCenter = 90;
  26. int Down = 0;
  27.  
  28. void setup() {
  29. base.attach(9); // attaches the servo on pin 9 to the servo object
  30. claw.attach(10);
  31. clawRotate.attach(5);
  32. pivot.attach(6);
  33. upperPivot.attach(7);
  34.  
  35. }
  36. enum state{DECIDING, GOINGDEFAULT, GOINGTOSPECIFIC, GOINGTOOBJECT, OPENINGCLAW, CLOSINGCLAW};
  37. int currentState = DECIDING;
  38. void loop() {
  39. goingToDefault();
  40. goingToObject();
  41. goingToSpecific();
  42. openingClaw();
  43. closingClaw();
  44. }
  45.  
  46.  
  47. void goingToDefault(){
  48. if(goingToDefaultFlag == true) {
  49. base.write(0);
  50. pivot.write(0);
  51. upperPivot.write(0);
  52. claw.write(0);
  53. clowRotate.write(0);
  54. delay(1000);
  55. goingToDefaultFlag = false;
  56. }
  57. }
  58.  
  59. void goingToObject(){ //two flags need to be true going to object and going to default one.
  60. if(goingToObjectFlag == true){
  61. goingToDefault();
  62. delay(500);
  63. base.write(basePos);
  64. pivot.write(pivotPos);
  65. claw.write(clawPos);
  66. }
  67. }
  68.  
  69. void goingToSpecific() {//two flags need to be true goingtoobject and goingtodefault one.
  70. if(goingToSpecificFlag == true){
  71. goingToDefault(); //going to set the motor to default
  72. base.write(basePos);
  73. delay(500);
  74. goingToSpecifcFlag = false;
  75. }
  76. }
  77.  
  78. void armFunction(){
  79. if(armActivated == true) {
  80. switch(currentState) {
  81. case DECIDING:
  82.  
  83. break;
  84.  
  85. case GOINGTODEFAULT:
  86. break;
  87.  
  88. case GOINGTOSPECIFIC:
  89. break;
  90.  
  91. case GOINGTOOBJECT:
  92. break;
  93.  
  94. case OPENINGCLAW:
  95. break;
  96.  
  97. case CLOSINGCLAW:
  98. break;
  99. }
  100. }
  101. }
Add Comment
Please, Sign In to add comment