Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX, USBRX); 00004 00005 // Se definen la entradas analógicas 00006 00007 AnalogIn dataX(A1); 00008 AnalogIn dataY(A2); 00009 AnalogIn dataZ(A3); 00010 00011 void bucle() { 00012 pc.baud(4800); 00013 double x,y,z; 00014 double x_g_value,y_g_value,z_g_value; 00015 double roll, pitch; 00016 while(1) { 00017 x = dataX.read(); 00018 y = dataY.read(); 00019 z = dataZ.read(); 00020 00021 // Calculamos las aceleraciones en g 00022 x_g_value = ( ( ( (double)(x * 5)/1024) - 1.65 ) / 0.330 ); 00023 y_g_value = ( ( ( (double)(y * 5)/1024) - 1.65 ) / 0.330 ); 00024 z_g_value = ( ( ( (double)(z * 5)/1024) - 1.80 ) / 0.330 ); 00025 00026 //A partir de los valores del acelerometro, se calculan los angulos Y, X 00027 //respectivamente, con la formula de la tangente. 00028 roll = ( ( (atan2(y_g_value,z_g_value) * 180) / 3.14 ) + 180 ); 00029 pitch = ( ( (atan2(z_g_value,x_g_value) * 180) / 3.14 ) + 180 ); 00030 00031 pc.printf("Accelerometer X : %f\n\r", x); 00032 pc.printf("Accelerometer Y : %f\n\r", y); 00033 pc.printf("Accelerometer Z : %f\n\r", z); 00034 pc.printf("Roll: %f\n\r",roll); 00035 pc.printf("pitch: %f\n\r",pitch); 00036 pc.printf("\n\n"); 00037 pc.printf("\r\n"); 00038 wait(1); 00039 } 00040 } 00041 00042 int main() { 00043 bucle(); 00044 }
Generated on Thu Oct 6 2022 03:36:01 by
1.7.2