File tree Expand file tree Collapse file tree 1 file changed +25
-13
lines changed
libraries/MSA300/examples/msa_basic Expand file tree Collapse file tree 1 file changed +25
-13
lines changed Original file line number Diff line number Diff line change 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+
411acc_t data;
512MSA300 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}
You can’t perform that action at this time.
0 commit comments