简单写了一个读取GY-25 倾斜度模块数据,应该有bug,需要的可以自行修改
/// <summary>
///仰角定位点,参数为仰角角度
/// <summary>
private void BuildElevationTarget(double Eltemp)
{
// Draw target point
BuildElevation();
lblAngleSensorEl.Text = Eltemp.ToString() "°";
int radius = 4;
ElevationTargetGraphics = Graphics.FromImage(ElevationBaseBitmap);
ElevationTagerPen = new Pen(Color.FromArgb(30, 30, 30), 2f);
ElevationTagerBrush = new SolidBrush(Color.LimeGreen);
ElevationTagerBrush1 = new SolidBrush(Color.Red);
ElevationTargetGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
int x = 0; //圆心x
int y = ElevationHeight / 2; //圆心y
int r = 100 - radius;//半径
int tmpX = Convert.ToInt32(x r * Math.Cos((Eltemp) * 3.14 / 180));
int tmpY = Convert.ToInt32(y - r * Math.Sin((Eltemp) * 3.14 / 180));
//lblElevation.Text = String.Format("{0:00.0}", Eltemp) "°";
//lblElevation.Location = new Point(tmpX, tmpY );
ElevationTargetGraphics.DrawLine(new Pen(Color.Green, 1), new Point(0, 100), new Point(tmpX - radius / 2, tmpY - radius / 2));
lblElevation.Text = String.Format("{0:00.0}", Eltemp) "°";
if (Eltemp >= 0)
{
lblElevation.Location = new Point(tmpX, tmpY lblElevation.Size.Height / 2);
lblElevation.ForeColor = Color.Lime;
}
else
{
lblElevation.Location = new Point(tmpX - radius * 10, tmpY lblElevation.Size.Height);
lblElevation.ForeColor = Color.Red;
}
if (Eltemp >= 0)
{
ElevationTargetGraphics.DrawEllipse(ElevationTagerPen, tmpX - radius, tmpY - radius, radius * 2, radius * 2);
ElevationTargetGraphics.FillEllipse(ElevationTagerBrush, tmpX - radius, tmpY - radius, radius * 2, radius * 2);
}
else
{
ElevationTargetGraphics.DrawEllipse(ElevationTagerPen, tmpX - radius, tmpY - radius, radius * 2, radius * 2);
ElevationTargetGraphics.FillEllipse(ElevationTagerBrush1, tmpX - radius, tmpY - radius, radius * 2, radius * 2);
}
ElevationTagerPen.Dispose();
ElevationTagerBrush.Dispose();
}【文件目录】角度传感器├── GY-25倾斜角度传感器模块使用手册2.pdf
└── 角度传感器
├── AngleSensor
│ ├── AngleSensor.csproj
│ ├── App.config
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── SerialPortUtil.cs
│ ├── bin
│ │ └── Debug
│ │ ├── AngleSensor.exe
│ │ ├── AngleSensor.exe.config
│ │ ├── AngleSensor.pdb
│ │ ├── AngleSensor.vshost.exe
│ │ ├── AngleSensor.vshost.exe.config
│ │ └── AngleSensor.vshost.exe.manifest
│ └── obj
│ └── Debug
│ ├── AngleSensor.Form1.resources
│ ├── AngleSensor.Properties.Resources.resources
│ ├── AngleSensor.csproj.FileListAbsolute.txt
│ ├── AngleSensor.csproj.GenerateResource.Cache
│ ├── AngleSensor.exe
│ ├── AngleSensor.pdb
│ ├── DesignTimeResolveAssemblyReferences.cache
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── TempPE
│ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
├── 角度传感器.sln
└── 角度传感器.v12.suo
8 directories, 32 files
评论