-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gesture_code.ino
169 lines (126 loc) · 3.3 KB
/
Gesture_code.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// setup for APDS9930 sensor :
//#include <Wire.h>
// Setup for ULtrasonic sensors :
const int trigger1 = 3; //Trigger pin of 1st Sesnor
const int echo1 = 4; //Echo pin of 1st Sesnor
const int trigger2 = 5; //Trigger pin of 2nd Sesnor
const int echo2 = 6; //Echo pin of 2nd Sesnor
long time_taken;
int dist,distL,distR;
void setup() {
Serial.begin(9600);
// ULtrasonic sensor :
pinMode(trigger1, OUTPUT);
pinMode(echo1, INPUT);
pinMode(trigger2, OUTPUT);
pinMode(echo2, INPUT);
}
/*###Function to calculate distance###*/
void calculate_distance(int trigger, int echo)
{
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
time_taken = pulseIn(echo, HIGH);
dist= time_taken*0.034/2;
if (dist>50)
dist = 50;
}
void loop() {
// Ultra-sonic sensor actions code :
// Left Sensor :
calculate_distance(trigger1,echo1);
distL =dist; //get distance of left sensor
String LName = "L:";
String LValue = LName + distL ;
Serial.println(LValue);
//delay(500);
// Right Sensor :
calculate_distance(trigger2,echo2);
distR =dist; //get distance of left sensor
String RName = "R:";
String RValue = RName + distR;
Serial.println(RValue);
// delay(1200);
// Action : Pause/Play
if ((distL >40 && distR>40) && (distL <50 && distR<50)) //Detect both hands
{Serial.println("Play/Pause"); delay(300);}
calculate_distance(trigger1,echo1);
distL =dist;
calculate_distance(trigger2,echo2);
distR =dist;
//Control Modes for Left Sensor :
// Action : Escape
if (distL <= 7){
Serial.println("Escape"); delay(300);
}
// Action : Control Rewind 1x
if (distL >= 10 && distL <= 15){
while(distL <= 18 )
{
calculate_distance(trigger1,echo1);
distL = dist;
if (distL >= 10 && distL <= 15){
String LName = "L:";
String LValue = LName + distL ;
Serial.println(LValue);
Serial.println("CTabs"); delay(300);
}
}
}
// Action : Increase/Decrease Volume
if (distL >= 20 && distL <= 30){
delay(200);
while(distL <= 30 )
{
calculate_distance(trigger1,echo1);
distL = dist;
// Decrease Volume :
if (distL < 25 && distL > 20)
{
Serial.println(distL);
Serial.println("Vdown"); delay(300);
}
// Increase Volume :
if (distL < 30 && distL > 25)
{
Serial.println(distL);
Serial.println("Vup"); delay(300);
}
}
}
// -------------------------------------------------------
//Control Modes for Right Sensor :
// Action : Enter
if (distR <= 7){
Serial.println("Enter"); delay(300);
}
// Action : Control Forward 1x
if (distR >= 10 && distR <= 15){
Serial.println("Tab"); delay(300);
}
// Action : Continuous Fast Forwar/Rewind Volume
if (distR >= 20 && distR <= 30){
while(distR <= 30 )
{
calculate_distance(trigger2,echo2);
distR = dist;
// Decrease Volume :
if (distR < 25 && distR > 20)
{
Serial.println(distR);
Serial.println("FForward"); delay(300);
}
// Increase Volume :
if (distR < 30 && distR > 25)
{
Serial.println(distR);
Serial.println("FRewind"); delay(300);
}
}
}
// Wait second before next reading
delay(1000);
}