📄 calculateforangle.c
字号:
#include "common.h"
void CalculateforAngle(void)
{
Xh=ADC_Xaxis*Xsf-Xoff;
Yh=ADC_Yaxis*Ysf-Yoff;
if(Xh==0)
{
if(Yh>0)
Angle=90;
else
Angle=270;
}
else
{
if(Xh>0)
{
if(Yh>=0)
Angle=atan(Yh/Xh)*(180/M_PI);
else
Angle=360-atan(-Yh/Xh)*(180/M_PI);
}
else
{
if(Yh>0)
Angle=180-atan(-Yh/Xh)*(180/M_PI);
else
Angle=180+atan(Yh/Xh)*(180/M_PI);
}
}
}
void GetCurrentPointer(void)
{
uint LED_number,Point_Angle;
Point_Angle=Angle;
Point_Angle<<=2;
Point_Angle/=30;
if((Point_Angle<=39)&(Point_Angle>=24))
{
LED_number=Point_Angle-24;
G2_1=0;
G2_2=1;
G2_3=1;
}
else if((Point_Angle<=23)&(Point_Angle>=8))
{
LED_number=Point_Angle-8;
G2_1=1;
G2_2=1;
G2_3=0;
}
else
{
if((Point_Angle<=7)&(Point_Angle>=0))
LED_number=Point_Angle+8;
else
LED_number=Point_Angle-40;
G2_1=1;
G2_2=0;
G2_3=1;
}
PORTD&=0xf0;
PORTD|=LED_number;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -