mirror of
https://github.com/sipeed/Maixduino.git
synced 2026-03-03 09:04:00 +01:00
outputs values as formatted strings
This commit is contained in:
@@ -1,27 +1,39 @@
|
||||
#include <MSA300.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// This is the length of the string that will be created
|
||||
// included minus and decimal point
|
||||
const signed char formattedStringLength = 11;
|
||||
|
||||
// The number of digits after the deimal point to print
|
||||
const unsigned char numVarsAfterDecimal = 6;
|
||||
|
||||
acc_t data;
|
||||
MSA300 msa;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
static char outstr[formattedStringLength];
|
||||
|
||||
char * formatValue(float value)
|
||||
{
|
||||
dtostrf(value, formattedStringLength, numVarsAfterDecimal, outstr);
|
||||
return outstr;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Wire.begin();
|
||||
msa.begin();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
void loop()
|
||||
{
|
||||
data = msa.getAcceleration();
|
||||
Serial.print("Xa:");
|
||||
Serial.print(data.x);
|
||||
Serial.print("Ya:");
|
||||
Serial.print(data.y);
|
||||
Serial.print("Za:");
|
||||
Serial.println(data.z);
|
||||
|
||||
Serial.printf("Xa:%s ", formatValue(data.x));
|
||||
Serial.printf("Ya:%s ", formatValue(data.y));
|
||||
Serial.printf("Za:%s", formatValue(data.z));
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user