-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluetooth.h
124 lines (111 loc) · 1.96 KB
/
bluetooth.h
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
#ifndef _bluetooth_H
#define _bluetooth_H
#include "common.h"
#include "steppermotor_init.h"
#include "Servo.h"
extern int myStepper1ShouldRun;
char value;
float vel = 100;
float v = 0;
float w = 0;
const int pump = 51;
float vel_max = 255;
int dutycycle = 0;
int motor_dir;
enum
{
MOTOR_FORWARD = 0,
MOTOR_BACKWARD,
MOTOR_LEFT,
MOTOR_RIGHT
};
void read_bluetooth()
{
if (Serial.available())
{
value = Serial.read();
#if PRINT_DEBUG_INFO
Serial.print(value);
#endif
if (value == 'Z')
{
digitalWrite(pump, HIGH);
}
if (value == 'X')
{
digitalWrite(pump, LOW);
}
if (value == 'W')
{
v = vel;
w = 0;
motor_dir = MOTOR_FORWARD;
}
else if (value == 'S')
{
v = -vel;
w = 0;
motor_dir = MOTOR_BACKWARD;
}
else if (value == 'D')
{
v = 0;
w = vel*2;
motor_dir = MOTOR_RIGHT;
}
else if (value == 'A')
{
v = 0;
w = -vel*2;
motor_dir = MOTOR_LEFT;
}
else if (value == 'T') //Stop_robot
{
v = 0;
w = 0;
}
else if (value == '+')
{
Serial.print(value);
delay(200);
while (Serial.available())
{
value = Serial.read();
#if PRINT_DEBUG_INFO
Serial.print(value);
#endif
}
// turn_off_robot();
}
else if (value == 'I') //ARM UP
{
move_servo();
}
else if (value == 'K') //ARM STOP
{
stop_servo();
}
else if (value == 'J') //ARM LEFT
{
if (!digitalRead(PROXY_LEFT))
return;
steps = 0;
digitalWrite(dirx, HIGH);
enable_xaxis_stepper();
proxy_to_read = PROXY_LEFT;
}
else if (value == 'L') //ARM RIGHT
{
if (!digitalRead(PROXY_RIGHT))
return;
digitalWrite(dirx, LOW);
enable_xaxis_stepper();
proxy_to_read = PROXY_RIGHT;
}
else if (value == 'B')
{
stop_arm_stepper();
}
}
}
#endif // _bluetooth_H