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.
Fork of COG4050_adxl355_adxl357-ver2 by
main.cpp
00001 #include "mbed.h" 00002 #include <math.h> 00003 #include <inttypes.h> 00004 #include "ADXRS290.h" 00005 00006 Serial pc(USBTX, USBRX); 00007 00008 ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_SCLK); // PMOD port 00009 Timeout t_loop; 00010 00011 00012 00013 void meas() { 00014 gyro.rate_data = gyro.scan(); 00015 float x =float(gyro.rate_data.rt_x)*0.005*0.1; 00016 float y =float(gyro.rate_data.rt_y)*0.005*0.1; 00017 float z =float(gyro.rate_data.rt_z)*0.005*0.1; 00018 pc.printf("°data = %f \t %f \t %f \r\n", x , y , z); 00019 } 00020 00021 int main(){ 00022 pc.baud(9600); 00023 pc.printf("SPI ADXRS Demo\n"); 00024 // device info 00025 pc.printf("GET device ID\n"); 00026 uint8_t d; 00027 d=gyro.read_reg(gyro.ADI_ID); 00028 pc.printf("AD id = %x \r\n",d); 00029 d=gyro.read_reg(gyro.MEMS_ID); 00030 pc.printf("MEMS id = %x \r\n",d); 00031 d=gyro.read_reg(gyro.DEV_ID); 00032 pc.printf("device id = %x \r\n",d); 00033 d=gyro.read_reg(gyro.REV_ID); 00034 pc.printf("revision id = %x \r\n",d); 00035 // device data 00036 pc.printf("GET device data [x, y, z, t] \r\n"); 00037 do { 00038 t_loop.attach(&meas, 0.1); // setup to call measurement function after 0.1 seconds 00039 } while(1); 00040 }
Generated on Wed Jul 13 2022 09:03:43 by
1.7.2
