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.
main.cpp@0:c4316ce25c75, 2016-12-08 (annotated)
- Committer:
- viniciushl
- Date:
- Thu Dec 08 12:26:27 2016 +0000
- Revision:
- 0:c4316ce25c75
1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| viniciushl | 0:c4316ce25c75 | 1 | #include "mbed.h" |
| viniciushl | 0:c4316ce25c75 | 2 | #include "HMC5883L.h" |
| viniciushl | 0:c4316ce25c75 | 3 | #define N 3 |
| viniciushl | 0:c4316ce25c75 | 4 | |
| viniciushl | 0:c4316ce25c75 | 5 | HMC5883L compass(p9, p10); |
| viniciushl | 0:c4316ce25c75 | 6 | DigitalOut myled(LED1); |
| viniciushl | 0:c4316ce25c75 | 7 | |
| viniciushl | 0:c4316ce25c75 | 8 | int main() |
| viniciushl | 0:c4316ce25c75 | 9 | { |
| viniciushl | 0:c4316ce25c75 | 10 | int get_mag[N] = {0}; // Buffer of the compass |
| viniciushl | 0:c4316ce25c75 | 11 | int mag[N] = {0}; |
| viniciushl | 0:c4316ce25c75 | 12 | compass.setDefault(); |
| viniciushl | 0:c4316ce25c75 | 13 | wait(0.1); // Wait some time for all sensors (Need at least 5ms) |
| viniciushl | 0:c4316ce25c75 | 14 | |
| viniciushl | 0:c4316ce25c75 | 15 | while(1) |
| viniciushl | 0:c4316ce25c75 | 16 | { |
| viniciushl | 0:c4316ce25c75 | 17 | myled = 1; |
| viniciushl | 0:c4316ce25c75 | 18 | wait(0.2); |
| viniciushl | 0:c4316ce25c75 | 19 | |
| viniciushl | 0:c4316ce25c75 | 20 | compass.readData(get_mag); |
| viniciushl | 0:c4316ce25c75 | 21 | for( int i=0;i<N;i++ ){ mag[i] = (int16_t)get_mag[i]; } |
| viniciushl | 0:c4316ce25c75 | 22 | |
| viniciushl | 0:c4316ce25c75 | 23 | printf("Compass = %d, %d, %d\r\n", mag[0], mag[1], mag[2]); |
| viniciushl | 0:c4316ce25c75 | 24 | myled = 0; |
| viniciushl | 0:c4316ce25c75 | 25 | wait(0.2); |
| viniciushl | 0:c4316ce25c75 | 26 | } |
| viniciushl | 0:c4316ce25c75 | 27 | } |
