Using an ADXL335 acelerometer, it returns x, y and z data as m/s2.

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Committer:
lim14373
Date:
Sun Sep 03 05:51:26 2017 +0000
Revision:
2:a67bd8b193e1
Parent:
0:fb6bbc10ffa0
Child:
3:bb9f3d9562da
Usar este

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lim14373 2:a67bd8b193e1 1 /*
lim14373 2:a67bd8b193e1 2
lim14373 2:a67bd8b193e1 3 Primero descargas el driver: https://developer.mbed.org/handbook/Windows-serial-configuration
lim14373 2:a67bd8b193e1 4 Lo instalas mientras está contectada la mbed a la pc
lim14373 2:a67bd8b193e1 5
lim14373 2:a67bd8b193e1 6 Conexiones:
simon 0:fb6bbc10ffa0 7
lim14373 2:a67bd8b193e1 8 Vout - Vcc
lim14373 2:a67bd8b193e1 9 p18 - Z_Out
lim14373 2:a67bd8b193e1 10 p19 - Y_Out
lim14373 2:a67bd8b193e1 11 p20 - X_Out
lim14373 2:a67bd8b193e1 12 GND - GND
lim14373 2:a67bd8b193e1 13 */
simon 0:fb6bbc10ffa0 14
lim14373 2:a67bd8b193e1 15 #include "mbed.h"
lim14373 2:a67bd8b193e1 16
lim14373 2:a67bd8b193e1 17 AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis respectively.
lim14373 2:a67bd8b193e1 18 AnalogIn inputy(p19);
lim14373 2:a67bd8b193e1 19 AnalogIn inputz(p18);
lim14373 2:a67bd8b193e1 20 Serial pc(USBTX,USBRX); //Serial class for transmission of serial data
lim14373 2:a67bd8b193e1 21
simon 0:fb6bbc10ffa0 22 int main() {
lim14373 2:a67bd8b193e1 23 pc.baud(9600); // fixing a constant baud rate of 9600 bps at which mbed will interact with computer
lim14373 2:a67bd8b193e1 24 float x=0,y=0,z=0; // variables for x,y,z axes
lim14373 2:a67bd8b193e1 25
lim14373 2:a67bd8b193e1 26 while(1)
lim14373 2:a67bd8b193e1 27 {
lim14373 2:a67bd8b193e1 28
lim14373 2:a67bd8b193e1 29 x = (inputx-0.495)*98.07;
lim14373 2:a67bd8b193e1 30 y = (inputy-0.495)*98.07;
lim14373 2:a67bd8b193e1 31 z = (inputz-0.495)*98.07;
lim14373 2:a67bd8b193e1 32 pc.printf("i,%f,%f,%f \n",x,y,z);
lim14373 2:a67bd8b193e1 33
lim14373 2:a67bd8b193e1 34 }
simon 0:fb6bbc10ffa0 35 }