Hi CNC and arduino expert. I have problem with my code. I could not draw circle but instead i get weird shape. .. Can anyone check whats wrong with my code.... to much coding..hmpph.. ( I don't want to use any library, GRBL, GCODE intreprete, no Brensenham),only Arduino). Moving in x y at the same time, i don't have any problem, but if drawing circle ( im using movexy to draw circular graph) and divide the circle into some section (division) for smoother circle but got weird shape. Here is the code
int ix,iy,ixx,iyy,iyold,ixold, delayx;
float xf,yf,ixf,iyf,iyyf,ifl,directionx,directiony;
void circle(int div,float delaycirc, float rad){ // (division(more=smooth), delay, radius)
float xxold=0;
float yyold=0;
for(int idiv=0; idiv<=(div); idiv++){
float divfloat=idiv;
float xx=(cos(2*PI/div*divfloat)-0)*rad; int x=abs(xx-xxold); xxold=xx;
float yy=(sin(2*PI/div*divfloat)-0)*rad; int y=abs(yy-yyold); yyold=yy;
if( xx<0){directionx=1;}else{directionx=0;}
if( yy<0){directiony=1;}else{directiony=0;}
movexy(x,y,delaycirc, directionx, directiony);
}
delay(1000);
}
void setup(){}
void loop(){
circle(360, 100, 10000); // (360 section, 100 delay. radius of 10000 step)}
void movexy(float xf, float yf, int delaxy, int directionx, int directiony){
iyold=0;
ixold=0;
if(xf>=yf){
for(ifl=1; ifl<=(xf+1); ifl++){
iyf=ifl*(yf/xf);
if(round(iyf)>iyold){
digitalWrite(8, directiony);
digitalWrite(9, HIGH);}
digitalWrite(6, directionx);
digitalWrite(7, HIGH);
delayMicroseconds(delaxy);
if(round(iyf)>iyold){
digitalWrite(9, LOW);
iyold=iyold+1;}
digitalWrite(7, LOW);
delayMicroseconds(delaxy); }}
else{
for(ifl=1; ifl<=(yf+1); ifl++){
ixf=ifl*(xf/yf);
if(round(ixf)>ixold){
digitalWrite(6, directionx);
digitalWrite(7, HIGH);}
digitalWrite(8, directiony);
digitalWrite(9, HIGH);
delayMicroseconds(delaxy);
if(round(ixf)>ixold){
digitalWrite(7, LOW);
ixold=ixold+1;}
digitalWrite(9, LOW);
delayMicroseconds(delaxy);
}}
}