Hi there! ![]()
I have more of a logic question- I'm building a 'musical instrument', with a stepper motor located in the middle of a circle, and cups ectr are standing around it in a circle. the stepper is supposed to move to each cup, and then hits it (im leaving out the specifics of this bc its not needed to make it simpler). so the stepper motor needs to move backwards and forwards, and still reach the correct destination every time.
there are 8 cups, so the stepper motor has to move 45° to reach a new cups.
the bug ive found is that, when i'm playing the note at 180° and 270°, the stepper moves likes this: 180-270-0-90-180-270.... when it should just be moving like this: 180-270-180-270...
my function looks like this:
void moveHere(int target) {
//determines where the stepper has to move in order to reach its target - depending on where it is currently
//first we check whether we have to move at all
if (target == previousPos) {
rotationDistance = 0;
//then we check where we were last
//ive seperated the cases (previousPos <= 180) and (previousPos >180) so that the stepper motor uses the most direct way
} else if (previousPos <= 180) {
if (target <= 180) {
rotationDistance = target - previousPos;
} else if (target > 180) {
rotationDistance = 360 - target + previousPos;
}
} else if (previousPos > 180) {
if (target <= 180){
rotationDistance = 360 - previousPos + target;
} else if (target > 180) {
rotationDistance = target - previousPos;
}
}
return rotationDistance;
}
so I'm guessing I've gotten some of my calculation wrong
but I can't figure out where the mistake is..
if you want me to post the rest of my code, pls ask^^
thank you!!