-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_uno_with_tsop.ino
107 lines (62 loc) · 1.4 KB
/
arm_uno_with_tsop.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//Arm
#include <PWMServo.h>
#include <SoftwareSerial.h>
SoftwareSerial BT(2,3); // 2 is Rx and 3 is Tx
int sensor1 = 12; // for shuttlecock detection
int count = 0;
int tsop_reciever = 11; //for releasing shuttlecock
//int p=0;
PWMServo myServo; //for gripping shuttlecock
int flag = 0;
int cflag = 0;
void setup() {
Serial.begin(9600);
BT.begin(38400);
myServo.attach(9);
pinMode(sensor1, INPUT);
pinMode(tsop_reciever, INPUT);
pinMode(9,OUTPUT);
int a = digitalRead(sensor1);
if(a == HIGH) //no shuttlecock detected
{
myServo.write(0);//servo open
flag=1;
}
}
void loop() {
int a = digitalRead(sensor1);
int b = digitalRead(tsop_reciever);
if(a == LOW) //shuttle gripped and motor will go in tz1
{
myServo.write(40); //servo close
flag=2;
}
if(a == HIGH && flag == 2)
{
myServo.write(40);
flag = 2;
}
if(b == LOW) //for releasing shuttlecock
{
cflag = 1;
}
if(b == HIGH && cflag == 1 && flag == 2)
{
count++;
//delay(50);
cflag = 0;
}
if(count == 8 && b==HIGH)
{
myServo.write(0); //servo open
flag=0;
count = 0;
}
Serial.print(flag);
Serial.print(" ");
Serial.print(count);
Serial.print(" ");
Serial.print(cflag);
Serial.println();
BT.write(flag);
}