Laser Show på pcDuino (7 / 8 steg)
Steg 7: Provningsmetod
#include
< core.h > #include
< math.h >
#define uchar unsigned char
#define uint unsigned int
#define WR_Control 10
#define aktiverar 0
#define inaktivera 1
#define channel_x hög
#define channel_y låg
#define Select_Channel 11
#define LED_ON digitalWrite(12,HIGH)
#define LED_OFF digitalWrite(12,LOW)
void AD7528_write_byte(uchar dat)
{
uchar i.
för (jag = 2; jag < 10; i ++)
{
om ((dat&0x01)) digitalWrite(i,HIGH);
annat digitalWrite(i,LOW);
dat >> = 1;
}
}
void AD7528_write_data (uchar kanal, uchar dat)
{
LED_ON;
digitalWrite(Select_Channel,channel);
digitalWrite(WR_Control,Enable);
AD7528_write_byte(dat);
digitalWrite(WR_Control,Disable);
LED_OFF;
}
void out_xy (int x, int y)
{
digitalWrite(WR_Control,Disable);
AD7528_write_byte(y);
digitalWrite(Select_Channel,channel_y);
digitalWrite(WR_Control,Enable);
digitalWrite(WR_Control,Disable);
AD7528_write_byte(x);
digitalWrite(Select_Channel,channel_x);
digitalWrite(WR_Control,Enable);
digitalWrite(WR_Control,Disable);
}
void Create_Point (uchar x, uchar y)
{
AD7528_write_data(channel_x,x);
delayMicroseconds(1);
AD7528_write_data(channel_y,y);
delayMicroseconds(1);
}
void draw_line (uint x1, uint y1, uint x2, uint y2)
{
uint t;
int xerr = 0, yerr = 0, delta_x, delta_y, avstånd;
int incx, incy, uRow, uCol;
delta_x = x2-x1; Å'ÆËà £Ã – ø±êà "öà ¿
delta_y = y2-y1;
uRow = x1;
uCol = y1;
IF(delta_x>0) incx = 1; Éèà – ÃƑÂΜ ¥ ²Š"•Å" à ò
annat if(delta_x==0) incx = 0; //Ž¹Ö±à ß
annat {incx =-1; delta_x =-delta_x;}
IF(delta_y>0) incy = 1;
annat if(delta_y==0) incy = 0; //ˮƊ"à ß
annat {incy =-1; delta_y =-delta_y;}
om (delta_x > delta_y) avstånd = delta_x; Ã'¡È¡» ù±Ÿà "öà ¿à – ø±êà – á
annat avstånd = delta_y;
för (t = 0; t < = avstånd + 1; t ++) //»Âà ßÊä³ö
{
delayMicroseconds(5);
out_xy (uRow, uCol); //» Âµà £
LED_ON;
delayMicroseconds(15);
LED_OFF;
delayMicroseconds(10);
xerr += delta_x;
yerr += delta_y;
IF(xerr>Distance)
{
xerr-= avstånd;
uRow += incx;
}
IF(yerr>Distance)
{
yerr-= avstånd;
uCol += incy;
}
}
}
void DrawCircle (int cx, int cy, int r)
{
flottör t;
int x, y, px, py;
t = 0;
PX = r + cx;
py = cy;
medan (t < = 2)
{
x = cos(t*PI) * r + cx;
y = sin(t*PI) * r + cy;
draw_line(x,y,px,py);
t = t + 0,01;
PX = x;
py = y;
}
draw_line(x,y,r+CX,CY);
}
void setup()
{
uchar i.
för (jag = 2; jag < 13; i ++)
{
pinMode(i,OUTPUT);
}
digitalWrite(WR_Control,Disable);
LED_OFF;
}
void draw_star (uchar x, uchar y, uchar storlek)
{
LED_ON;
draw_line(x+size*2,y+size*5/4,x,y+size*5/4);
draw_line(x,y+size*5/4,x+size*2,y);
draw_line(x+size*2,y,x+size,y+size*2);
draw_line(x+size,y+size*2,x,y);
draw_line(x,y,x+size*2,y+size*5/4);
LED_OFF;
}
#define tid 450
uchar tabell [] = {
1,10,60,30,120,50,10,90,60,80,49,100,50,30,2,100,40,80,20,120,
20,23,90,50,20,60,100,120,90,10,60,30}.
void loop()
{
för (int j = 0; j < 16; j ++)
{
för (int jag = 0; jag < 20; i ++)
{
draw_star(Table[j],Table[j+1],30);
delayMicroseconds(100);
}
}
Delay(300);
int i;
för (jag = 0; jag < 100; i ++)
{
Visa "A"
out_xy(62,0);
delayMicroseconds(time);
LED_ON;
delayMicroseconds(500);
draw_line(62,0,52,0);
draw_line(52,0,46,17);
draw_line(46,17,16,17);
draw_line(16,17,10,0);
draw_line(10,0,1,0);
draw_line(1,0,25,63);
draw_line(25,63,37,63);
draw_line(37,63,62,0);
delayMicroseconds(800);
LED_OFF;
Delay(1);
out_xy(43,25);
delayMicroseconds(time);
LED_ON;
delayMicroseconds(500);
draw_line(43,25,31,56);
draw_line(31,56,19,25);
draw_line(19,25,43,25);
delayMicroseconds(800);
LED_OFF;
}
Delay(300);
för (jag = 0; jag < 120; i ++)
{
out_xy(9,16);
delayMicroseconds(1000);
LED_ON;
draw_line(9,16,37,16);
draw_line(37,16,37,167);
draw_line(37,167,68,167);
draw_line(68,167,68,16);
draw_line(68,16,105,16);
draw_line(105,16,105,109);
draw_line(105,109,129,109);
draw_line(129,109,129,16);
draw_line(129,16,153,16);
draw_line(153,16,153,202);
draw_line(153,202,179,202);
draw_line(179,202,179,20);
draw_line(179,20,205,20);
delayMicroseconds(1000);
LED_OFF;
}
Delay(300);
} < /math.h >< /core.h >