-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhand_gesture.ino
108 lines (92 loc) · 1.92 KB
/
hand_gesture.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
const int inputPin1=12;
const int outputPin1=9;
const int inputPin2=5;
const int outputPin2=7;
//distance
long time_dur;
int dis1,dis2;
float r;
unsigned long temp=0;
int temp1=0;
int l=0;
void distance_cal(void);
void distance_cal(void)
{
digitalWrite(inputPin1,LOW);
delayMicroseconds(2);
digitalWrite(inputPin1,HIGH);
delayMicroseconds(10);
digitalWrite(inputPin1,LOW);
time_dur=pulseIn(outputPin1,HIGH,5000);
r=3.4*time_dur/2;
dis1=r/100.00;
digitalWrite(inputPin2,LOW);
delayMicroseconds(2);
digitalWrite(inputPin2,HIGH);
delayMicroseconds(10);
digitalWrite(inputPin2,LOW);
time_dur=pulseIn(outputPin2,HIGH,5000);
r=3.4*time_dur/2;
dis2=r/100.00;
delay(100);
}
void setup()
{
Serial.begin(9600);
pinMode(inputPin1,OUTPUT);
pinMode(outputPin1,INPUT);
pinMode(inputPin2,OUTPUT);
pinMode(outputPin2,INPUT);
delay(1000);
}
void loop()
{
distance_cal();
if(dis2<=30 && dis2>=10)
{
temp=millis();
while(millis()<=(temp+300))
distance_cal();
if(dis2<=30 && dis2>=10)
{
temp=dis2;
while(dis2<=30 || dis2==0)
{
distance_cal();
if((temp+6)<dis2)
{
Serial.println("down");
}
else if((temp-6)>dis2)
{
Serial.println("up");
}
}
}
else
{
Serial.println("next");
}
}
else if(dis1<=30 && dis1>=10)
{
temp=millis();
while(millis()<=(temp+300))
{
distance_cal();
if(dis2<=30 && dis2>=10)
{
Serial.println("change");
l=1;
break;
}
}
if(l==0)
{
Serial.println("previous");
while(dis1<=30 && dis1>=10)
distance_cal();
}
l=0;
}
}