Serpentine
/
foodcontroller
Tilt steering control
Diff: main.cpp
- Revision:
- 0:8e22f474256a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 07 15:31:48 2016 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +#include "MMA8451Q.h" + +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +int main() +{ + MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); + PwmOut rled(LED_RED); + PwmOut gled(LED_GREEN); + bool right; + + while (1) { + + if(acc.getAccX() <= 0.1 && acc.getAccX() >= -0.1) { + if (right == true) { + rled = 0; + } else + gled = 0; + } + + if (acc.getAccX() > 0.1) { + rled = 0; + gled = 1; + right = true; + } + + if (acc.getAccX() < -0.1) { + rled = 1; + gled = 0; + right = false; + } + wait(0.1); + } + +}