11 years, 11 months ago.

Is the code to display accelerometer outputs correct?

  1. include "mbed.h"

Serial pc(USBTX, USBRX);

AnalogIn x(p18); Defining AnalogIn y(p19); input AnalogIn z(p20); pins

float a,b,c; to store values of x,y and z axis

int main() { a=x.read(); read x-axis value b=y.read(); read y-axis value c=z.read(); read z-axis value pc.printf("X=%f\n",a); print x-axis value on terminal pc.printf("Y=%f\n",b); print y-axis value on terminal pc.printf("Z=%f\n",c); print z-axis value on terminal

}

1 Answer

11 years, 11 months ago.

Use <<code>> and <</code>> around your code to make it readable.

It looks to be correct, assuming you have an analog accelerometer. But of course if you ask this question you probably have a problem, in that case describe your problem.