Andrew Mkpanam
/
Accelerometer_pt1
Final
main.cpp@4:72b8fb7423dd, 2020-02-19 (annotated)
- Committer:
- WilliamMarshQMUL
- Date:
- Wed Feb 19 20:54:44 2020 +0000
- Revision:
- 4:72b8fb7423dd
- Parent:
- 3:d5c746840139
- Child:
- 6:a0f642150296
Update RTOS and wait API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WilliamMarshQMUL | 0:a1caba5c4e48 | 1 | #include "mbed.h" |
WilliamMarshQMUL | 0:a1caba5c4e48 | 2 | #include "MMA8451Q.h" |
WilliamMarshQMUL | 0:a1caba5c4e48 | 3 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 4 | PinName const SDA = PTE25; |
WilliamMarshQMUL | 0:a1caba5c4e48 | 5 | PinName const SCL = PTE24; |
WilliamMarshQMUL | 0:a1caba5c4e48 | 6 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 7 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
WilliamMarshQMUL | 0:a1caba5c4e48 | 8 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 9 | int main(void) |
WilliamMarshQMUL | 0:a1caba5c4e48 | 10 | { |
WilliamMarshQMUL | 0:a1caba5c4e48 | 11 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 12 | PwmOut rled(LED1); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 13 | PwmOut gled(LED2); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 14 | PwmOut bled(LED3); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 15 | Serial pc(USBTX, USBRX); // tx, rx |
WilliamMarshQMUL | 0:a1caba5c4e48 | 16 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 17 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 18 | pc.printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 19 | |
WilliamMarshQMUL | 0:a1caba5c4e48 | 20 | while (true) { |
WilliamMarshQMUL | 0:a1caba5c4e48 | 21 | float x, y, z; |
WilliamMarshQMUL | 0:a1caba5c4e48 | 22 | x = acc.getAccX(); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 23 | y = acc.getAccY(); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 24 | z = acc.getAccZ(); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 25 | rled = 1.0f - abs(x); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 26 | gled = 1.0f - abs(y); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 27 | bled = 1.0f - abs(z); |
WilliamMarshQMUL | 4:72b8fb7423dd | 28 | ThisThread::sleep_for(300); // wait(0.3); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 29 | pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); |
WilliamMarshQMUL | 0:a1caba5c4e48 | 30 | } |
WilliamMarshQMUL | 0:a1caba5c4e48 | 31 | } |