Skip to content

Commit d0a4f8a

Browse files
committed
formatter; cleaned up output print line; increased delay on output
1 parent ff5794e commit d0a4f8a

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed
Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
#include <Wire.h> // Used to establish serial communication on the I2C bus
21
#include "SparkFun_TMAG5273_Arduino_Library.h" // Used to send and recieve specific information from our sensor
2+
#include <Wire.h> // Used to establish serial communication on the I2C bus
33

44
TMAG5273 sensor; // Initialize hall-effect sensor
55

66
// I2C default address
77
uint8_t i2cAddress = TMAG5273_I2C_ADDRESS_INITIAL;
88

9-
void setup()
9+
void setup()
1010
{
11-
Wire.begin();
12-
// Start serial communication at 115200 baud
13-
Serial.begin(115200);
14-
15-
// Begin example of the magnetic sensor code (and add whitespace for easy reading)
16-
Serial.println("TMAG5273 Example 1: Basic Readings");
17-
Serial.println("");
18-
19-
// If begin is successful (0), then start example
20-
if(sensor.begin(i2cAddress, Wire) == 1)
21-
{
22-
Serial.println("Begin");
23-
}
24-
else // Otherwise, infinite loop
25-
{
26-
Serial.println("Device failed to setup - Freezing code.");
27-
while(1); // Runs forever
28-
}
29-
11+
Wire.begin();
12+
// Start serial communication at 115200 baud
13+
Serial.begin(115200);
14+
15+
// Begin example of the magnetic sensor code (and add whitespace for easy reading)
16+
Serial.println("TMAG5273 Example 1: Basic Readings");
17+
Serial.println("");
18+
19+
// If begin is successful (0), then start example
20+
if (sensor.begin(i2cAddress, Wire) == 1)
21+
{
22+
Serial.println("Begin");
23+
}
24+
else // Otherwise, infinite loop
25+
{
26+
Serial.println("Device failed to setup - Freezing code.");
27+
while (1)
28+
; // Runs forever
29+
}
3030
}
3131

32-
33-
void loop()
32+
void loop()
3433
{
35-
// Checks if mag channels are on - turns on in setup
36-
if(sensor.getMagneticChannel() != 0)
37-
{
38-
sensor.setTemperatureEn(true);
39-
40-
float magX = sensor.getXData();
41-
float magY = sensor.getYData();
42-
float magZ = sensor.getZData();
43-
float temp = sensor.getTemp();
44-
45-
Serial.print("(");
46-
Serial.print(magX);
47-
Serial.print(", ");
48-
Serial.print(magY);
49-
Serial.print(", ");
50-
Serial.print(magZ);
51-
Serial.println(") mT");
52-
Serial.print(temp);
53-
Serial.println(" C");
54-
}
55-
else
56-
{
57-
// If there is an issue, stop the magnetic readings and restart sensor/example
58-
Serial.println("Mag Channels disabled, stopping..");
59-
while(1);
60-
}
61-
62-
delay(100);
34+
// Checks if mag channels are on - turns on in setup
35+
if (sensor.getMagneticChannel() != 0)
36+
{
37+
sensor.setTemperatureEn(true);
38+
39+
float magX = sensor.getXData();
40+
float magY = sensor.getYData();
41+
float magZ = sensor.getZData();
42+
float temp = sensor.getTemp();
43+
44+
Serial.print("Data - Magnetic: [ X: ");
45+
Serial.print(magX);
46+
Serial.print(", Y: ");
47+
Serial.print(magY);
48+
Serial.print(", Z: ");
49+
Serial.print(magZ);
50+
Serial.print(" ] mT, Temp: ");
51+
Serial.print(temp);
52+
Serial.println(" C");
53+
}
54+
else
55+
{
56+
// If there is an issue, stop the magnetic readings and restart sensor/example
57+
Serial.println("Mag Channels disabled, stopping..");
58+
while (1)
59+
;
60+
}
61+
62+
delay(300);
6363
}

0 commit comments

Comments
 (0)