Go Down

Topic: circle code for Etch a sketch? (Read 939 times) previous topic - next topic

spinjim

I am just learning arduino and electronics so I built a computer controlled etch a sketch. Not very original I know, but a good way to learn. All I used was 2 stepper motors (Jameco #155432) and 2 darlington arrays (uln 2004) a powers supply and the arduino board. I have been successful at programming it to a point. I first made straight lines, then boxes, then diagonals and then diamond shapes but I am stuck on how to make a circle. Can anybody out there offer some help to the mathematically challenged?
I want to draw images too, but that is after I learn how to do circles. I included some simple code that will make a diagonal line.
Thanks,


Code: [Select]
// positive hor steps will move right, negative left aproximatly 1720 steps from side to side
// positive ver steps will move up, negitive down. Aproximatly 1150 steps bottom to top
// the acuracy is not very good. Mechanically the stylus is controlled by strings that stretch and give instead of breaking.

#include <Stepper.h>
#define STEPS 200
Stepper hor(STEPS, 2, 3, 4, 5);
Stepper vert(STEPS, 8, 9, 10, 11);
int rpm=30;
void setup()
{
// set the speed of the motor to the variable rpm
 hor.setSpeed(rpm);
 vert.setSpeed(rpm);
}
void loop()
{
 // draw a diagonal line
for (int i=0; i <= 800; i++){  
 hor.step(1);
 vert.step(1);
  }
}

westfw


hungerburg

there "http://www.mikrocontroller.net/topic/42447#610705" is an implementation of Bresenham for a full circle - its not perfect for small circles though

Go Up