accelorometer and touch pad
Dependencies: MMA8451Q TSIServo mbed
Fork of FRDM_MMA8451Q by
main.cpp@10:ac7dd2ffbd14, 2018-09-27 (annotated)
- Committer:
- cindyC12
- Date:
- Thu Sep 27 19:43:24 2018 +0000
- Revision:
- 10:ac7dd2ffbd14
- Parent:
- 9:1f50587ada14
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 2:41db78380a6e | 1 | #include "mbed.h" |
chris | 2:41db78380a6e | 2 | #include "MMA8451Q.h" |
cindyC12 | 8:0d24df2d4f18 | 3 | #include "TSISensor.h" |
chris | 2:41db78380a6e | 4 | |
chris | 2:41db78380a6e | 5 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
chris | 2:41db78380a6e | 6 | |
chris | 4:367de1084ea9 | 7 | int main(void) { |
emilmont | 5:bf5becf7469c | 8 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
cindyC12 | 8:0d24df2d4f18 | 9 | PwmOut r(LED_RED); |
cindyC12 | 8:0d24df2d4f18 | 10 | PwmOut g(LED_GREEN); |
cindyC12 | 8:0d24df2d4f18 | 11 | PwmOut b(LED_BLUE); |
cindyC12 | 8:0d24df2d4f18 | 12 | TSISensor tsi; |
cindyC12 | 10:ac7dd2ffbd14 | 13 | |
chris | 4:367de1084ea9 | 14 | |
emilmont | 5:bf5becf7469c | 15 | while (true) { |
cindyC12 | 9:1f50587ada14 | 16 | float x, y, z ; |
cindyC12 | 9:1f50587ada14 | 17 | x = abs(acc.getAccX()); |
cindyC12 | 10:ac7dd2ffbd14 | 18 | r= 1.0 - (x*tsi.readPercentage()); |
cindyC12 | 9:1f50587ada14 | 19 | y = abs(acc.getAccY()); |
cindyC12 | 10:ac7dd2ffbd14 | 20 | g = 1.0 - (y*tsi.readPercentage()); |
cindyC12 | 9:1f50587ada14 | 21 | z = abs(acc.getAccZ()); |
cindyC12 | 10:ac7dd2ffbd14 | 22 | b = 1.0 - (z*tsi.readPercentage()); |
chris | 3:f2d3e041d8f2 | 23 | wait(0.1); |
chris | 2:41db78380a6e | 24 | } |
chris | 2:41db78380a6e | 25 | } |