EDA365电子论坛网
标题:
基于matlab时钟设计
[打印本页]
作者:
ubeautqq
时间:
2021-9-22 09:40
标题:
基于matlab时钟设计
9 X2 ]; r, X: Z' k- O
一、简介
. K0 a% y* n7 z& f# p; F
基于matlab时钟设计
0 B" w B4 o/ S" e
7 U9 H1 h) n5 g
7 w! x9 m6 v) w/ K
二、源代码
) H- P p( C) p' w
+ X8 t G. _: k# R
function timeCompass()
%h_comaps = compass([x1;x2;x2],[y1;y2;y3])
%x1y1 x2y2 x3y3 为三个指针向量 h_compass为句柄
%%创建坐标轴做为显示表盘,并隐藏
hAxes = axes('visible','off','DrawMode','fast');
%%绘制表盘中心点
hAxesDot = axes('Visible','off','DrawMode','fast');
axis equal;
line(0,0,'Parent',hAxesDot,'Marker','o','MarkerFaceColor','k','MarkerSize',15)
try
while 1
%%获取当前时间
time = floor(clock); %向下取整 clock:将当前时间和日期返回到一个(6元)数组中。
hour = time(4); % 2008 8 26 12 31 32.75
min = time(5);
sec = time(6);
%fprintf(hour);
argHour = pi/2 - (hour + min / 60) * pi / 6;
argMin = pi/2 - (min + sec / 60) * pi / 30;
argSec = pi/2 -sec * pi/30;
%根据计算的指针弧度值创建表盘和指针
hCompass = compass(hAxes,[0.5*cos(argHour);0.8*cos(argMin);cos(argSec)],[0.5*sin(argHour);0.8*sin(argMin);sin(argSec)]);
set(hCompass,'LineWidth',3);%设置线宽
set(hCompass(3),'LineWidth',1);%设置线宽
set(hCompass(1),'Color','k');%时针红色
set(hCompass(2),'Color','k');
delete(findall(hAxes,'Type','text','-or','linestyle',':'));
%%绘制数值
ang = pi /3 ;
for i=1:12
if rem(i,3) %3d的倍数 字号12
text(0.8*cos(ang),0.8*sin(ang),num2str(i),'horizontalAlignment','center','FontSize',12,'Parent',hAxes);
else
text(0.8*cos(ang),0.8*sin(ang),num2str(i),'horizontalAlignment','center','FontSize',20,'FontWeight','bold','Color','g','Parent',hAxes);
end
ang =ang -pi/6;
end
( H6 g6 Z8 C$ a5 k0 R
. W6 |- I! o" B7 ?" i+ |, G0 m2 u: A
0 [5 f$ a3 c7 |7 T9 ^) i1 f8 A" e
三、运行结果
; @. w' W6 l/ Y
, Q- T# E* b9 ~
3.jpg
(12.52 KB, 下载次数: 8)
下载附件
保存到相册
2021-9-22 09:39 上传
: q9 L* U+ o H' o/ M/ m0 Z( f
, H) I% f' N i
作者:
smileqq
时间:
2021-9-22 11:17
基于matlab时钟设计
作者:
younicp
时间:
2021-9-22 11:19
基于matlab时钟设计
作者:
NingW
时间:
2021-9-22 11:19
基于matlab时钟设计
作者:
ldezgr
时间:
2021-9-26 15:01
LZ辛苦,学习学习
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2