Skip to content

Commit 5f648cd

Browse files
Merge pull request #1 from sparkfun/fix_angle_calc
Fix Angle Calculations Example 3. Changed data type, fixed logic operation to bitwise, added function to convert int to float, and fixed units in the example to degree.
2 parents 159254b + 22e1f92 commit 5f648cd

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

examples/Example3_AngleCalculations/Example3_AngleCalculations.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void loop()
5353
float angleCalculation = sensor.getAngleResult();
5454

5555
Serial.print("XYX: ");
56-
Serial.print(angleCalculation);
57-
Serial.println(" mT");
56+
Serial.print(angleCalculation, 4);
57+
Serial.println("°");
5858

5959
}
6060
else

src/SparkFun_TMAG5273_Arduino_Library.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,10 +2644,10 @@ float TMAG5273::getZData()
26442644
/// @return Angle measurement result in degrees (float value)
26452645
float TMAG5273::getAngleResult()
26462646
{
2647-
int8_t angleLSB = 0;
2648-
int8_t angleMSB = 0;
2647+
uint8_t angleLSB = 0;
2648+
uint8_t angleMSB = 0;
26492649

2650-
angleLSB = readRegister(TMAG5273_REG_ANGLE_RESULT_LSB);
2650+
angleLSB = readRegister(TMAG5273_REG_ANGLE_RESULT_LSB) & 0b11111111;
26512651
angleMSB = readRegister(TMAG5273_REG_ANGLE_RESULT_MSB);
26522652

26532653
// Variable to hold the full angle MSB and LSB registers
@@ -2663,7 +2663,7 @@ float TMAG5273::getAngleResult()
26632663
angleReg = (angleMSB << 8) | angleLSB;
26642664

26652665
// Removing the uneeded bits for the fraction value
2666-
decValue = (angleReg && (0b0000000000001111)) / 16;
2666+
decValue = float(angleLSB & 0b1111) / 16;
26672667

26682668
// Shift off the decimal value (last 4 bits)
26692669
angleVal = angleReg >> 4;

0 commit comments

Comments
 (0)