Skip to content

Commit 4f5585a

Browse files
authored
outputs values as formatted strings
1 parent 485cf19 commit 4f5585a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed
Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
#include <MSA300.h>
22
#include <Wire.h>
33

4+
// This is the length of the string that will be created
5+
// included minus and decimal point
6+
const signed char formattedStringLength = 11;
7+
8+
// The number of digits after the deimal point to print
9+
const unsigned char numVarsAfterDecimal = 6;
10+
411
acc_t data;
512
MSA300 msa;
613

7-
void setup() {
8-
// put your setup code here, to run once:
14+
static char outstr[formattedStringLength];
15+
16+
char * formatValue(float value)
17+
{
18+
dtostrf(value, formattedStringLength, numVarsAfterDecimal, outstr);
19+
return outstr;
20+
}
21+
22+
void setup()
23+
{
924
Serial.begin(9600);
1025
Wire.begin();
1126
msa.begin();
12-
13-
14-
1527
}
1628

17-
void loop() {
18-
// put your main code here, to run repeatedly:
29+
void loop()
30+
{
1931
data = msa.getAcceleration();
20-
Serial.print("Xa:");
21-
Serial.print(data.x);
22-
Serial.print("Ya:");
23-
Serial.print(data.y);
24-
Serial.print("Za:");
25-
Serial.println(data.z);
32+
33+
Serial.printf("Xa:%s ", formatValue(data.x));
34+
Serial.printf("Ya:%s ", formatValue(data.y));
35+
Serial.printf("Za:%s", formatValue(data.z));
36+
Serial.println();
37+
2638
delay(100);
2739
}

0 commit comments

Comments
 (0)