Pages: [1]   Go Down
Author Topic: circle code for Etch a sketch?  (Read 891 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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);
   }
}
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look up "Bresenham circle"
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: