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
00001 #include "mbed.h" 00002 #include "MMA8451Q.h" 00003 00004 PinName const SDA = PTE25; 00005 PinName const SCL = PTE24; 00006 00007 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00008 00009 int main(void) 00010 { 00011 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); 00012 PwmOut rled(LED1); 00013 PwmOut gled(LED2); 00014 PwmOut bled(LED3); 00015 Serial pc(USBTX, USBRX); // tx, rx 00016 00017 00018 pc.printf("MMA8451 ID: %d\n", acc.getWhoAmI()); 00019 00020 while (true) { 00021 float x, y, z; 00022 x = acc.getAccX(); 00023 y = acc.getAccY(); 00024 z = acc.getAccZ(); 00025 rled = 1.0f - abs(x); 00026 gled = 1.0f - abs(y); 00027 bled = 1.0f - abs(z); 00028 ThisThread::sleep_for(300); // wait(0.3); 00029 pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); 00030 } 00031 }
Generated on Wed Jul 13 2022 02:24:20 by
