Step 15Delicious!
here are a few examples, though, to get you started:
draw_square(int side)
{
pwm(255,0,1,0,side);
pwm(0,255,0,1,side);
pwm(255,0,0,0,side);
pwm(0,255,0,0,side);
}
//I use trig functions in this example, and you'll need to find some avr library that supports them
//or just whip up a table
draw_circle(int radius)
{
double x,y,xp, yp, int mag;
unsigned char xval, yval;
xp=radius;
yp=0;
unsigned char xdir,ydir;
for(double theta=0;theta<360;theta++)
{
x=radius*cos(theta);
y=radius*sin(theta);
if(x>xp)
xdir=1;
else
xdir=0;
if(y>yp)
ydir=1;
else
ydir=0;
angle=atan((y-yp)/(x-xp));
xval=255*abs(cos(angle));
yval=255*abs(sin(angle));
mag=sqrt(pow((y-yp),2)+pow((x-xp),2));
pwm(xval,yval,xdir,ydir,mag);
}
}
Foster the dog wishes you good luck in your programming endeavors!
Valerie the dog suggests you listen to DJ Z-trip. Wait, that's not Valerie. That's me.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|






















































