1
2
3#include <Servo.h>
4
5Servo servoClaw;
6Servo servoHeight;
7Servo servoTurn;
8
9
10int clawAngle = 150;
11int heightAngle = 160;
12int turnAngle = 0;
13
14
15
16void setup() {
17
18 Serial.begin (9600);
19
20 servoClaw.attach(3);
21 servoHeight.attach(4);
22 servoTurn.attach(5);
23
24
25
26 heightAngle = move(servoHeight,heightAngle,heightAngle);
27 turnAngle = move(servoTurn,turnAngle,turnAngle);
28 clawAngle = move(servoClaw,clawAngle,clawAngle);
29
30
31
32 turnAngle = move(servoTurn,turnAngle,90);
33 delay(1000);
34 heightAngle = move(servoHeight,heightAngle,90);
35 delay(1000);
36 clawAngle = move(servoClaw,clawAngle,10);
37 delay(1000);
38 heightAngle = move(servoHeight,heightAngle,160);
39 delay(1000);
40
41
42
43 turnAngle = move(servoTurn,turnAngle,0);
44 delay(1000);
45 heightAngle = move(servoHeight,heightAngle,140);
46 delay(1000);
47 clawAngle = move(servoClaw,clawAngle,150);
48 delay(1000);
49 heightAngle = move(servoHeight,heightAngle,160);
50 delay(1000);
51
52
53
54 turnAngle = move(servoTurn,turnAngle,160);
55 delay(1000);
56 heightAngle = move(servoHeight,heightAngle,90);
57 delay(1000);
58 clawAngle = move(servoClaw,clawAngle,10);
59 delay(1000);
60 heightAngle = move(servoHeight,heightAngle,160);
61 delay(1000);
62
63
64
65 turnAngle = move(servoTurn,turnAngle,0);
66 delay(1000);
67 heightAngle = move(servoHeight,heightAngle,140)
68 delay(1000);
69 clawAngle = move(servoClaw,clawAngle,150);
70 delay(1000);
71 heightAngle = move(servoHeight,heightAngle,160);
72 delay(1000);
73
74}
75
76
77void loop() {
78
79}
80
81
82
83
84
85
86
87
88int move(Servo servoTemp,int currentAngle, int desiredAngle)
89{
90 if(currentAngle<desiredAngle)
91 {
92 while(currentAngle<=desiredAngle)
93 {
94 servoTemp.write(currentAngle);
95 currentAngle++;
96 delay(10);
97 }
98 }
99 else
100 {
101 while(currentAngle>=desiredAngle)
102 {
103 servoTemp.write(currentAngle);
104 currentAngle--;
105 delay(10);
106 }
107 }
108
109 return currentAngle;
110
111}
112