Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700 Hexi_OLED_SSD1351
Fork of Hexi_Accelero_Magneto_Example by
main.cpp@1:6da908234299, 2016-08-13 (annotated)
- Committer:
- maclobdell
- Date:
- Sat Aug 13 15:59:34 2016 +0000
- Revision:
- 1:6da908234299
- Parent:
- 0:207337d58f96
- Child:
- 2:f9c24c129575
initial simple example that prints to terminal
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| maclobdell | 0:207337d58f96 | 1 | #include "mbed.h" |
| maclobdell | 0:207337d58f96 | 2 | #include "FXOS8700CQ.h" |
| maclobdell | 0:207337d58f96 | 3 | |
| maclobdell | 1:6da908234299 | 4 | /* Check out the full featured example application for interfacing to the |
| maclobdell | 1:6da908234299 | 5 | * Accelerometer/Magnetometer device at the following URL |
| maclobdell | 1:6da908234299 | 6 | * https://developer.mbed.org/users/trm/code/fxos8700cq_example/ |
| maclobdell | 1:6da908234299 | 7 | */ |
| maclobdell | 1:6da908234299 | 8 | |
| maclobdell | 0:207337d58f96 | 9 | DigitalOut led1(LED1); |
| maclobdell | 0:207337d58f96 | 10 | |
| maclobdell | 0:207337d58f96 | 11 | // Pin connections & address for Hexiwear |
| maclobdell | 0:207337d58f96 | 12 | FXOS8700CQ fxos(PTC11, PTC10, FXOS8700CQ_SLAVE_ADDR0); // SDA, SCL, (addr << 1) |
| maclobdell | 0:207337d58f96 | 13 | // Storage for the data from the sensor |
| maclobdell | 0:207337d58f96 | 14 | SRAWDATA accel_data; |
| maclobdell | 0:207337d58f96 | 15 | SRAWDATA magn_data; |
| maclobdell | 0:207337d58f96 | 16 | |
| maclobdell | 0:207337d58f96 | 17 | // main() runs in its own thread in the OS |
| maclobdell | 0:207337d58f96 | 18 | // (note the calls to Thread::wait below for delays) |
| maclobdell | 0:207337d58f96 | 19 | int main() { |
| maclobdell | 0:207337d58f96 | 20 | |
| maclobdell | 0:207337d58f96 | 21 | fxos.enable(); |
| maclobdell | 0:207337d58f96 | 22 | while (true) { |
| maclobdell | 0:207337d58f96 | 23 | led1 = !led1; |
| maclobdell | 0:207337d58f96 | 24 | // Example data printing |
| maclobdell | 0:207337d58f96 | 25 | fxos.get_data(&accel_data, &magn_data); |
| maclobdell | 0:207337d58f96 | 26 | printf("A X:%5d,Y:%5d,Z:%5d M X:%5d,Y:%5d,Z:%5d\r\n", |
| maclobdell | 0:207337d58f96 | 27 | accel_data.x, accel_data.y, accel_data.z, |
| maclobdell | 0:207337d58f96 | 28 | magn_data.x, magn_data.y, magn_data.z); |
| maclobdell | 0:207337d58f96 | 29 | |
| maclobdell | 0:207337d58f96 | 30 | Thread::wait(500); |
| maclobdell | 0:207337d58f96 | 31 | } |
| maclobdell | 0:207337d58f96 | 32 | } |
