1#include<Servo.h>
2Servo servo1;
3Servo servo2;
4int count=0;
5const int dirPin = 2;
6const int stepPin = 3;
7
8
9const int STEPS_PER_REV = 200;
10
11void setup() {
12
13
14 pinMode(stepPin,OUTPUT);
15 pinMode(dirPin,OUTPUT);
16 servo1.attach(6);
17 servo2.attach(5);
18
19}
20
21
22
23void pickAndReadCard()
24{
25
26 servo1.write(180);
27 delay(1000);
28 servo2.write(0);
29 delay(1000);
30 servo1.write(0);
31 delay(1000);
32 servo2.write(180);
33}
34
35void move(int nDirection, float nSteps){
36
37
38 digitalWrite(dirPin,nDirection);
39
40
41 for(int x = 0; x < STEPS_PER_REV * nSteps; x++) {
42 digitalWrite(stepPin,HIGH);
43 delayMicroseconds(2000);
44 digitalWrite(stepPin,LOW);
45 delayMicroseconds(2000);
46 }
47}
48
49void releaseCard()
50{
51 servo2.write(0);
52 delay(2000);
53 servo1.write(180);
54 delay(1000);
55 servo2.write(180);
56 delay(1000);
57 servo1.write(0);
58}
59
60
61void loop() {
62
63if (count<1) {
64
65 move(LOW, 1.7);
66
67 pickAndReadCard();
68
69 delay(3000);
70
71 releaseCard();
72
73 move(LOW,0.9);
74
75 pickAndReadCard();
76
77 move(HIGH,0.9);
78
79
80 servo2.write(180);
81 delay(3000);
82
83 move(LOW,0.9);
84
85 releaseCard();
86
87 move(LOW,0.9);
88
89 pickAndReadCard();
90
91 delay(2000);
92
93 move(HIGH,1.9);
94
95 servo2.write(180);
96 delay(3000);
97
98 move(LOW,1.9);
99
100 releaseCard();
101
102 move(LOW,0.9);
103
104 pickAndReadCard();
105
106 delay(2000);
107
108 move(HIGH,2.9);
109
110 servo2.write(180);
111 delay(3000);
112
113 move(LOW,2.9);
114
115 releaseCard();
116
117 move(HIGH,4.5);
118
119 count++;
120
121}
122
123
124}