Yusuke Suzuki
/
balancer
The LEDs flashes faster, depending on the inclination of the sensor. Accelerometer: MMA8451Q
Revision 0:3e3ddecc2783, committed 2014-03-09
- Comitter:
- junshoc
- Date:
- Sun Mar 09 15:01:24 2014 +0000
- Commit message:
- The LEDs flash faster, depending on the inclination of the sensor.; ; Accelerometer : MMA8451Q
Changed in this revision
diff -r 000000000000 -r 3e3ddecc2783 MMA8451Q.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8451Q.lib Sun Mar 09 15:01:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
diff -r 000000000000 -r 3e3ddecc2783 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Mar 09 15:01:24 2014 +0000 @@ -0,0 +1,31 @@ +// +// balance meter +// + +#include "mbed.h" +#include "MMA8451Q.h" +#include <iostream> +#include "math.h" + +#define TIME 0.05 // wait (balanced) +#define MINIMUM_TIME 0.003 // wait (not balanced) + +PwmOut gled(LED1); +PwmOut rled(LED2); +MMA8451Q acc(PTE25, PTE24, 0x1D<<1); + +int main() +{ + gled.period_ms( 1 ); + rled.period_ms( 1 ); + + while (1) + { + for ( int i=0; i<360; i+=10 ) { + gled = cos( i*2.0*3.14/360 ) * 0.5 + 0.5; + rled = 1.0 - (cos( i*2.0*3.14/360 ) * 0.5 + 0.5); + + wait(max(TIME - (abs(acc.getAccX()) + abs(acc.getAccY())) * TIME, MINIMUM_TIME)); + } + } +}
diff -r 000000000000 -r 3e3ddecc2783 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Mar 09 15:01:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file