Skip to content

Instantly share code, notes, and snippets.

@pral2a
Last active August 29, 2015 13:57
Show Gist options
  • Save pral2a/9833118 to your computer and use it in GitHub Desktop.
Save pral2a/9833118 to your computer and use it in GitHub Desktop.
int xPosition = 0;
int yPosition = 0;
int totalStepsCircle = 25; // number steps to complete the circle
int centerX = 500; // half the frame lenght
int centerY = 500; // half the frame lenght
int radius = 250;
int currentStep = 0;
void setup() {
// put your setup code here, to run once:
}
void loop() {
updateCirclePosition();
/*
- Then just call the motors to update to position xPosition and yPosition
- Then call run
- You can easily move this function to processing and just send the commands acorsing to the x and y
- Take care that if you are not aware when the motor is done,
when the steps are accomplished, just set some interval,
call the update circle the commands every X seconds.
*/
}
void updateCirclePosition(){
if(currentStep > totalStepsCircle) currentStep = 0;
xPosition = (centerX + radius * cos(2 * PI * currentStep / totalStepsCircle));
yPosition = (centerY + radius * sin(2 * PI * currentStep / totalStepsCircle));
currentStep++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment