运行前需要添加图片,命名为img,就可以看到运行效果。
单片机源程序如下:
- % test_led_wheel
- % for your reference
- ri = 0.1;
- div_p = 180;
- % div_p = 256;
- div_r = 22;
- % div_r = 36;
- bit = 8;
- % read RGB from img
- img_w = size(img, 2);
- img_h = size(img, 1);
- img_cx = round(img_w / 2 - 1);
- img_cy = round(img_h / 2 - 1);
- img_r = min(img_cx, img_cy);
- figure;
- hold on;
- axis equal;
- whitebg('k');
- xlim([-1.1, 1.1]);
- ylim([-1.1, 1.1]);
-
- fid = fopen('b.txt','a+');
- ks=0;
- for i=1:div_p
- % plot([ri*cos(2*pi*i/div_p), cos(2*pi*i/div_p)], ...
- % [ri*sin(2*pi*i/div_p), sin(2*pi*i/div_p)]);
- for j=1:div_r
- pr = ((1-ri)/(div_r-1)*(j-1)+ri);
- px1 = cos(2*pi*(i-1)/div_p);
- px2 = cos(2*pi*(i)/div_p);
- py1 = sin(2*pi*(i-1)/div_p);
- py2 = sin(2*pi*(i)/div_p);
- % pc = [i/div_p,j/div_r,(2-i/div_p-j/div_r)/2];
- ix = min(round(img_cx + img_r*px1*pr)+1, img_w);
- iy = min(round(img_cy + img_r*py1*pr)+1, img_h);
- icr = img(iy, ix, 1);
- icg = img(iy, ix, 2);
- icb = img(iy, ix, 3);
- fprintf(fid,'0x%x,0x%x,0x%x,',icr,icg,icb');
- ks=ks+1;
- if ks>=22
- fprintf(fid,'&');
- ks=0;
- end
-
- pc = single([icr, icg, icb]/2^(8-bit)) * 2^(8-bit) / 256;
- plot( pr * px1, -pr * py1, '.', ...
- 'MarkerEdgeColor', pc );
- end;
- end;
- fclose(fid);
- % byte = div_r * div_p * bit / 8
- % dw = 0.7; % m
- % v = 40; % km/h
- % n = v/3.6/dw/pi % rps
- % dt = 1/n/div_p * 1000 % ms
复制代码
所有资料51hei提供下载:
read.rar
(724 Bytes, 下载次数: 9)
|