Mark Oehlberg
/
Accelerometer_to_color
This program changes the accelerometer data in to an RGB color
Revision 0:6c4e46da8d65, committed 2014-08-01
- Comitter:
- oehlberg
- Date:
- Fri Aug 01 18:29:07 2014 +0000
- Commit message:
- Accelerometer to RGB
Changed in this revision
diff -r 000000000000 -r 6c4e46da8d65 MMA8451Q.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8451Q.lib Fri Aug 01 18:29:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r 6c4e46da8d65 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 01 18:29:07 2014 +0000 @@ -0,0 +1,42 @@ +#include "mbed.h" +#include "MMA8451Q.h"//This is the onboard accelerometer + +#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)//This is the board I have and I guess they changed some pins around + PinName const SDA = PTE25; + PinName const SCL = PTE24; +#elif defined (TARGET_KL05Z) + PinName const SDA = PTB4; + PinName const SCL = PTB3; +#else + #error TARGET NOT DEFINED +#endif + +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +//Serial pc(USBTX, USBRX);//The accelerometer didn't have to do this...I guess this is how you could change baud rates +//int baudrate = 115200; + +int main(void) { + MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + //pc.baud(baudrate); + PwmOut rled(LED1);//pwms are 0-1 with 0 being off and 1 on + PwmOut gled(LED2); + PwmOut bled(LED3); + + printf("MMA8451 ID: %d\n", acc.getWhoAmI()); + float x,y,z,accx, accy, accz; + + while (true) { + + accx = abs(acc.getAccX()); + accy = abs(acc.getAccY()); + accz = abs(acc.getAccZ()); + + x = rled = 1.0 - accx; + y = gled = 1.0 - accy; + z = bled = 1.0 - accz; + + wait(0.5);//I don't think 12c can poll as fast as the processor can go. The delay is needed for this + printf("Red: %1.5f, Green: %1.5f, Blue: %1.5f\t Acceleration X: %1.10f Y: %fZ: %1.5f\n\r", x, y, z,accx,accy,accz);//so \n goes down one line, but does not get me to the beggining of a line. \r gets to the beginning of the line so the formatting is right + } +}
diff -r 000000000000 -r 6c4e46da8d65 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Aug 01 18:29:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877 \ No newline at end of file