-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS2E15-controlrobotwithcommands.ino
More file actions
90 lines (71 loc) · 1.96 KB
/
Copy pathS2E15-controlrobotwithcommands.ino
File metadata and controls
90 lines (71 loc) · 1.96 KB
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
#include <Servo.h>
Servo baseMotor;
Servo extendMotor;
Servo liftMotor;
Servo clawMotor;
//- soft limits for motors
int baseMotorMin = 0;
int baseMotorMax = 180;
int baseMotorMid = ((baseMotorMax - baseMotorMin) / 2) + baseMotorMin;
int extendMotorMax = 150;
int extendMotorMin = 50;
int extendMotorMid = ((extendMotorMax - extendMotorMin) / 2) + extendMotorMin;
int liftMotorMax = 180;
int liftMotorMin = 90;
int liftMotorMid = ((liftMotorMax - liftMotorMin) / 2) + liftMotorMin;
int clawClose = 180;
int clawOpen = 90;
//- speed
int speed = 10;
void setup() {
baseMotor.attach(9);
extendMotor.attach(10);
liftMotor.attach(11);
clawMotor.attach(6);
pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
//Serial.println("Hello I am a robot arm.");
while (Serial.available()>0) {
char myLetter;
myLetter = Serial.read(); //- read 1 character
Serial.print("I just received: ");
Serial.println(myLetter);
if (myLetter == '1') {
//-open the claw
clawMotor.write(clawOpen);
Serial.println("opening the claw!");
}
if (myLetter == '2') {
//-close the claw
clawMotor.write(clawClose);
Serial.println("closing the claw!");
}
if (myLetter == 'a') {
baseMotor.write(baseMotorMin);
Serial.println("Moving base motor to min!");
}
if (myLetter == 'b') {
baseMotor.write(baseMotorMid);
Serial.println("Moving base motor to mid!");
}
if (myLetter == 'c') {
baseMotor.write(baseMotorMax);
Serial.println("Moving base motor to max!");
}
if (myLetter == 'q') {
liftMotor.write(liftMotorMin);
Serial.println("Moving lift motor to min!");
}
if (myLetter == 'w') {
liftMotor.write(liftMotorMid);
Serial.println("Moving lift motor to mid!");
}
if (myLetter == 'e') {
liftMotor.write(liftMotorMax);
Serial.println("Moving lift motor to max!");
}
}
delay(100);
}