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 00005 PinName const SDA = PTE25; 00006 PinName const SCL = PTE24; 00007 00008 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00009 Ticker acctick; 00010 DigitalOut fallled(LED2); 00011 void acctick_isr(void); 00012 void acctick_isr(void) 00013 { 00014 float x, y, z,a; 00015 x = acc.getAccX(); 00016 y = acc.getAccY(); 00017 z = acc.getAccZ(); 00018 a=sqrt(pow(x,2)+pow(y,2)+pow(z,2)); 00019 wait(0.1f); 00020 printf("X: %1.2f, Y: %1.2f, Z: %1.2f, a: %1.2f \n", x, y, z,a); 00021 } 00022 int main(void) 00023 { 00024 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); 00025 fallled=1; 00026 acctick.attach(&acctick_isr,0.01); 00027 printf("MMA8451 ID: %d\n", acc.getWhoAmI()); 00028 00029 while (true); 00030 }
Generated on Tue Jul 19 2022 08:02:45 by
1.7.2