Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit ba04160

Browse files
Moved motor movent into funtions
1 parent 782abb1 commit ba04160

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

rodincom/rodincom.ino renamed to arduino_control/arduino_control.ino

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ char receivedChars[numChars];
1212

1313
boolean newData = false;
1414

15+
String recievedString = "";
16+
17+
1518
int m1_sensor_pin = A0;
1619
int m1_sensor_value1 = 0;
1720
int m1_sensor_value2 = 0;
21+
int m1_rotation_int = 0;
22+
String m1_rotation_direction = "";
23+
String m1_rotation = "";
24+
25+
int m2_sensor_pin = A0;
26+
int m2_sensor_value1 = 0;
27+
int m2_sensor_value2 = 0;
28+
int m2_rotation_int = 0;
29+
String m2_rotation_direction = "";
30+
String m2_rotation = "";
1831

1932
void setup() {
2033
Serial.begin(9600);
@@ -31,6 +44,10 @@ void loop() {
3144
showNewData();
3245
}
3346

47+
//////////////////////////////////////
48+
//////////////////////////////////////
49+
//////////////////////////////////////
50+
3451
void recvWithStartEndMarkers() {
3552
static boolean recvInProgress = false;
3653
static byte ndx = 0;
@@ -64,21 +81,26 @@ void recvWithStartEndMarkers() {
6481
}
6582

6683
void processData() {
67-
String recievedString = receivedChars;
84+
85+
86+
recievedString = receivedChars;
87+
88+
m1_rotation_direction = getValue(recievedString, ',', 0);
89+
m1_rotation = getValue(recievedString, ',', 1);
90+
m1_rotation_int = m1_rotation.toInt();
91+
92+
//comments
6893
Serial.println("<");
6994
Serial.print("RevievedString: ");
7095
Serial.println(recievedString);
71-
String m1_rotation_direction = getValue(recievedString, ',', 0);
72-
String m1_rotation = getValue(recievedString, ',', 1);
73-
int m1_rotation_int = m1_rotation.toInt();
7496
Serial.print("Number of Rotations: ");
7597
Serial.println(m1_rotation);
7698

7799
if (m1_rotation_direction == "Up") {
78100
Serial.println("<");
79101
Serial.print("Arduino: ");
80102
Serial.println("Moving Up!");
81-
pwm.setPWM(3, 0, 295);
103+
upMotor(3);
82104
while (1) {
83105
readValues();
84106
Serial.println(m1_sensor_value2);
@@ -91,14 +113,13 @@ void processData() {
91113
}
92114
delay(500);
93115
}
94-
pwm.setPWM(3, 0, 0);
95-
116+
stopMotor(3);
96117
}
97118
else if (m1_rotation_direction == "Down") {
98119
Serial.println("<");
99120
Serial.print("Arduino: ");
100121
Serial.println("Moving Down!");
101-
pwm.setPWM(3, 0, 270);
122+
downMotor(3);
102123
while (1) {
103124
readValues();
104125
Serial.println(m1_sensor_value2);
@@ -111,14 +132,14 @@ void processData() {
111132
}
112133
delay(500);
113134
}
114-
pwm.setPWM(3, 0, 0);
135+
stopMotor(3);
115136
}
116137

117-
else if (strcmp(receivedChars,"Stop")==0){
138+
else if (m1_rotation_direction == "Stop"){
118139
Serial.println("<");
119140
Serial.print("Arduino: ");
120141
Serial.println("Moving Stopping!");
121-
pwm.setPWM(3, 0, 0);
142+
stopMotor(3);
122143
}
123144
else
124145
{

arduino_control/motor_movement.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
void stopMotor(int motor_number) {
2+
pwm.setPWM(motor_number, 0, 0);
3+
}
4+
5+
void upMotor(int motor_number) {
6+
pwm.setPWM(motor_number, 0, 295);
7+
}
8+
9+
void downMotor(int motor_number) {
10+
pwm.setPWM(motor_number, 0, 270);
11+
}

0 commit comments

Comments
 (0)