-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_arduino.txt
59 lines (50 loc) · 1.22 KB
/
move_arduino.txt
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
#include <AFMotor.h>
AF_DCMotor motor(1);
AF_DCMotor motor_2(2);
const int MOVE_SPEED = 120;
const int ROTATE_SPEED = 180;
const int STOP_SPEED = 0;
void setup() {
motor.setSpeed(STOP_SPEED);
motor_2.setSpeed(STOP_SPEED);
motor.run(RELEASE);
motor_2.run(RELEASE);
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
int type_data = Serial.read() - 48;
switch(type_data){
case 1:
motor.setSpeed(MOVE_SPEED);
motor_2.setSpeed(MOVE_SPEED);
motor_2.run(FORWARD);
motor.run(FORWARD);
break;
case 2:
motor.setSpeed(MOVE_SPEED);
motor_2.setSpeed(MOVE_SPEED);
motor_2.run(BACKWARD);
motor.run(BACKWARD);
break;
case 3:
motor.setSpeed(ROTATE_SPEED);
motor_2.setSpeed(ROTATE_SPEED);
motor_2.run(FORWARD);
motor.run(BACKWARD);
break;
case 4:
motor.setSpeed(ROTATE_SPEED);
motor_2.setSpeed(ROTATE_SPEED);
motor_2.run(BACKWARD);
motor.run(FORWARD);
break;
case 5:
motor.setSpeed(STOP_SPEED);
motor_2.setSpeed(STOP_SPEED);
motor_2.run(RELEASE);
motor.run(RELEASE);
break;
}
}
}