Using an ADXL335 acelerometer, it returns x, y and z data as m/s2.
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 2:a67bd8b193e1
- Parent:
- 0:fb6bbc10ffa0
- Child:
- 3:bb9f3d9562da
--- a/main.cpp Sun Jan 01 20:57:57 2012 +0000 +++ b/main.cpp Sun Sep 03 05:51:26 2017 +0000 @@ -1,12 +1,35 @@ -#include "mbed.h" +/* + +Primero descargas el driver: https://developer.mbed.org/handbook/Windows-serial-configuration +Lo instalas mientras está contectada la mbed a la pc + +Conexiones: -DigitalOut myled(LED1); + Vout - Vcc + p18 - Z_Out + p19 - Y_Out + p20 - X_Out + GND - GND +*/ +#include "mbed.h" + +AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis respectively. +AnalogIn inputy(p19); +AnalogIn inputz(p18); +Serial pc(USBTX,USBRX); //Serial class for transmission of serial data + int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } + pc.baud(9600); // fixing a constant baud rate of 9600 bps at which mbed will interact with computer + float x=0,y=0,z=0; // variables for x,y,z axes + + while(1) + { + + x = (inputx-0.495)*98.07; + y = (inputy-0.495)*98.07; + z = (inputz-0.495)*98.07; + pc.printf("i,%f,%f,%f \n",x,y,z); + + } }