Skip to content

Commit

Permalink
Integrated broken rotate() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateo-S authored Mar 22, 2019
1 parent 6cfee9d commit ba8b1e2
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions chairmans2019.ino
Original file line number Diff line number Diff line change
Expand Up @@ -329,30 +329,35 @@ unsigned long sumRange(const unsigned long arr[], int ind1, int ind2) {
return sum;
}

/**
* Rotates seat motor r rotations based on encoder instead of time
*/

void rotate(int r){
curr = analogRead(ANALOG_PIN);
Serial.print("Current: ");
Serial.println(curr);
void rotate(int r) {
int endCount=PULSES_PER_ROTATION*r;
while (i/2 >= armatureRotations*r) {
cim.write(180);
currPositive = analogRead(ANALOG_PIN_POSITIVE);
currNegative = analogRead(ANALOG_PIN_NEGATIVE);
currDifference = (currPositive - currNegative);

if (curr > 400) { // If the current value is greater than 400 (peak), set isHigh to true
isHigh = true;
}
if (isHigh && curr < 200) { // If there's a peak and the current value is below 200 (trough), iterate and reset isHigh to false
encoderIncrement++;
isHigh = false;
}
if(currDifference > 0){
if(!posOrNeg){
i++;
}
posOrNeg = true;
}
else if (currDifference < 0){
if(posOrNeg){
i++;
}
posOrNeg = false;
}
Serial.println(i);

if (encoderIncrement > 174*r) { // Stop rotating after one revolution
encoderIncrement = 0;
cim.write(90);
Serial.println("Stop");
delay(4000);
} else {
cim.write(45); // Keep rotating if you haven't finished one revolution
}


// Stop rotating after r revolutions
i = 0;
cim.write(90);
completedRotation = true;
Serial.println("Stop");
delay(4000);

}

0 comments on commit ba8b1e2

Please sign in to comment.