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.
Revision 5:90b5419be471, committed 2019-10-16
- Comitter:
- MACRUM
- Date:
- Wed Oct 16 06:26:58 2019 +0000
- Parent:
- 4:80464da5d880
- Commit message:
- Add Magnetometer code
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 16 06:14:39 2019 +0000
+++ b/main.cpp Wed Oct 16 06:26:58 2019 +0000
@@ -7,43 +7,33 @@
#include "FXOS8700Q.h"
I2C i2c(PTE25, PTE24);
-FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);
+FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
-DigitalOut led_x(LED1);
-DigitalOut led_y(LED2);
-DigitalOut led_z(LED3);
+DigitalOut led(LED1);
int main(void)
{
- motion_data_counts_t acc_raw;
- int16_t raX, raY, raZ;
-
- // 加速度センサーの初期化
- acc.enable();
+ motion_data_counts_t mag_raw;
+ int16_t raX, raY, raZ;
+
+ // 磁気センサーの初期化
+ mag.enable();
while (true) {
// データの取得
- acc.getAxis(acc_raw);
- acc.getX(raX);
- acc.getY(raY);
- acc.getZ(raZ);
+ mag.getAxis(mag_raw);
+ mag.getX(raX);
+ mag.getY(raY);
+ mag.getZ(raZ);
// LED点滅
- if (raX > 0)
- led_x = 1;
+ if (raY > -10 && raY < 10)
+ led = 0;
else
- led_x = 0;
- if (raY > 0)
- led_y = 1;
- else
- led_y = 0;
- if (raZ > 0)
- led_z = 1;
- else
- led_z = 0;
+ led = 1;
// データの出力
printf("X: %d, Y: %d, Z:%d\n", raX, raY, raZ);
- wait(0.5f);
+ wait(0.2f);
}
}
\ No newline at end of file