-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchHand.ino
43 lines (34 loc) · 944 Bytes
/
searchHand.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
//tested.. not working yet, but seems to be realy nice code
#define HAND_DISTANCE 500
int searchHand()
{
int handPosition = 0;
digitalWrite(BRAKE_A, LOW);
digitalWrite(BRAKE_B, LOW);
SensorServo.write(SERVO_RIGHT);
do
{
for(int servoPosition = SERVO_RIGHT; servoPosition >= SERVO_LEFT; servoPosition--)
{
SensorServo.write(servoPosition);
delay(10);
sensorValue = analogRead(IR_SENSOR);
if(sensorValue >= HAND_DISTANCE)
{
handPosition = servoPosition;
return handPosition;
}
for(int servoPosition = SERVO_LEFT; servoPosition >= SERVO_RIGHT; servoPosition++)
{
SensorServo.write(servoPosition);
delay(10);
sensorValue = analogRead(IR_SENSOR);
if(sensorValue >= HAND_DISTANCE)
{
handPosition = servoPosition;
return handPosition;
}
}
}
}while(sensorValue < HAND_DISTANCE);
}