-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRobotArmArduinoTest.ino
More file actions
164 lines (126 loc) · 4.35 KB
/
RobotArmArduinoTest.ino
File metadata and controls
164 lines (126 loc) · 4.35 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/// COGNITIVE LEGO - ROBOT ARM - This Arduino code is meant to be LISTENING for serial commands from R
///
// #include <Servo.h>
#include <Keyboard.h>
int moveServo; // raw user input
const int ledPin2 = 2; // the number of the LED pin
const int ledPin3 = 3; // the number of the LED pin
const int ledPin4 = 4; // the number of the LED pin
const int ledPin5 = 5; // the number of the LED pin
const int ledPin6 = 6; // the number of the LED pin
const int ledPin13 = 13; // the number of the LED pin
void setup() {
Serial.begin(9600);
Serial.println(" Arduino Serial Servo Control");
Serial.println("Press < or > to move, spacebar to center");
Serial.println();
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin13, OUTPUT);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin13, HIGH);
}
void loop() {
// wait for serial input
if (Serial.available() > 0) {
moveServo = Serial.read(); // read the incoming byte:
////// LEDS AND MOTORS
if (moveServo == 97) // 'a' is Claw Close
{
digitalWrite(ledPin13, LOW); // this is for the polarity of volatage
digitalWrite(ledPin2, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin2, HIGH); // RESTORE
}
if (moveServo == 122) // 'z' is Claw Open
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage
digitalWrite(ledPin2, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin2, HIGH); // RESTORE
}
if (moveServo == 115) // 's' is Wrist CLose
{
digitalWrite(ledPin13, LOW); // this is for the polarity of volatage
digitalWrite(ledPin3, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin3, HIGH); // RESTORE
}
if (moveServo == 120) // 'x' is Wrist Open
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage
digitalWrite(ledPin3, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin3, HIGH); // RESTORE
}
if (moveServo == 100) // 'd' is Elbow Close
{
digitalWrite(ledPin13, LOW); // this is for the polarity of volatage
digitalWrite(ledPin4, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin4, HIGH); // RESTORE
}
if (moveServo == 99) // 'c' is Elbow Open
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage
digitalWrite(ledPin4, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin4, HIGH); // RESTORE
}
if (moveServo == 102) // 'f' is SHoulder Close
{
digitalWrite(ledPin13, LOW); // this is for the polarity of volatage
digitalWrite(ledPin5, LOW); ///
delay(1000);
digitalWrite(ledPin5, HIGH); // RESTORE
}
if (moveServo == 118) // 'v' is Shoulder Open
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage
digitalWrite(ledPin5, LOW); ///
delay(1000);
digitalWrite(ledPin5, HIGH); // RESTORE
}
if (moveServo == 103) // 'g' is ROtate Left
{
digitalWrite(ledPin13, LOW); // this is for the polarity of volatage
digitalWrite(ledPin6, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin6, HIGH); // RESTORE
}
if (moveServo == 98) // 'b' is ROtate RIght
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage
digitalWrite(ledPin6, LOW); ///
delay(1000);
digitalWrite(ledPin6, HIGH); // RESTORE
}
if (moveServo == 32) // ' ' is space for reset //
{
digitalWrite(ledPin13, HIGH); // this is for the polarity of volatage - each cycle
// OK - crude way to cycle through the relays for 2,3,4,5,6,
digitalWrite(ledPin2, LOW); /// CLAW
delay(1000);
digitalWrite(ledPin2, HIGH); // WRIST restore this before moving on
digitalWrite(ledPin3, LOW); // pull low to activate for 1 second
delay(1000);
digitalWrite(ledPin3, HIGH); // ELBOW
digitalWrite(ledPin4, LOW);
delay(1000);
digitalWrite(ledPin4, HIGH); // SHOULDER
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin5, HIGH); // WAIST
digitalWrite(ledPin6, LOW); //
delay(1000);
digitalWrite(ledPin6, HIGH); // restore before moving on
}
}
}