我想分享您的上述贡献如何帮助我制作 Arduino LCD 指南针。我希望这是正确的礼仪......我刚刚加入了stackoverflow,所以我要感谢你们这些好人。
当我站在几何巨人的肩膀上时,我能够制作出这个指南针样本:
Arduino TFT compass with multiple bearing
我反复调用的函数的代码(对于您在黄色小文本中看到的不同方位)是用 Arduino 编写的(有点像“C”)......并且非常易于翻译:
void PaintCompassNeedle( int pBearingInDegrees, int pRadius, TSPoint pCentrePt ) {
// ******************************************************************************
// * Formula for finding pointX on the circle based on degrees around the circle:
// * x_oncircle = x_origin + radius * cos (degrees * pi / 180)
// * y_oncircle = y_origin - radius * sin (degrees * pi / 180) //minus explained
// * Thanks to folks at stackoverflow...standing on the shoulders of giants. :)
float bearingInRads = (pBearingInDegrees) * PI / 180;
// Degrees vs Rads...The math folks use Rads in their formulas
// *******************************************************************
// * bearingPt is the point on the circle that we are trying to find
TSPoint bearingPt;
// Find the X on the circle starting with orgin (centre)
bearingPt.x = pCentrePt.x + pRadius * sin(bearingInRads);
// Notice the "minus" R * cos()...because TFT the y is upside down bearingPt.y =
pCentrePt.y - pRadius * cos(bearingInRads);
// * Extra Explanation: The TFT is the graphical display I'm using and it
// * calculates x & y from the top left of screen (portrait mode) as (0,0)
// * ...so by Subtracting from the Y orgin...I flip it vertically
// * Other folks using x,y as increasing to the right and up respectively
// * would keep the plus sign after the pCentrePt.y
// *************************************************************************
// ***************************************************************
// * This part will change for the final product...but leaving
// * it because when call numerous times it shows it working for
// * a number of different quadrants (displaying yellow degrees text)
tft.fillCircle( bearingPt.x, bearingPt.y, 5, RED);
tft.setCursor( bearingPt.x, bearingPt.y );
tft.setTextSize( 1 );
tft.setTextColor( YELLOW );
tft.print( pBearingInDegrees );
TSPoint innerPt;
innerPt.x = pCentrePt.x + pRadius/2 * sin(bearingInRads);
innerPt.y = pCentrePt.y - pRadius/2 * cos(bearingInRads);
tft.drawLine(innerPt.x, innerPt.y, bearingPt.x, bearingPt.y, RED);
}