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.
Max_sampling_rate.cpp
00001 #include "mbed.h" 00002 #include "MMA8451Q.h" 00003 #include "MAG3110.h" 00004 #include "TSISensor.h" 00005 00006 #define I2C0_SDA PTE25 00007 #define I2C0_SCL PTE24 00008 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00009 #define MAG3110_I2C_ADDRESS (0x0E<<1) 00010 #define LIGHT_SENSOR_PIN PTE22 00011 #define COUNT 1000 00012 00013 Serial pc_sr(USBTX, USBRX); 00014 MMA8451Q acc_sr(I2C0_SDA, I2C0_SCL, MMA8451_I2C_ADDRESS); 00015 MAG3110 mag_sr(I2C0_SDA, I2C0_SCL, MAG3110_I2C_ADDRESS); 00016 Timer timer_sr; 00017 TSISensor tsi_sr; 00018 AnalogIn lightSensor_sr(PTE22); 00019 00020 void light(int count) 00021 { 00022 int i = 0; 00023 00024 while (i < count) { 00025 lightSensor_sr.read(); 00026 i++; 00027 } 00028 } 00029 00030 void touch(int count) 00031 { 00032 int i = 0; 00033 while(i < count) { 00034 tsi_sr.readPercentage(); 00035 i++; 00036 } 00037 } 00038 00039 void magnetometer(int count) 00040 { 00041 int i = 0; 00042 00043 while(i < count) { 00044 mag_sr.readVal(MAG_OUT_X_MSB); 00045 mag_sr.readVal(MAG_OUT_Y_MSB); 00046 mag_sr.readVal(MAG_OUT_Z_MSB); 00047 i++; 00048 } 00049 } 00050 00051 void accelerometer(int count) 00052 { 00053 int i = 0; 00054 00055 while (i < 1000) { 00056 acc_sr.getAccX(); 00057 acc_sr.getAccY(); 00058 acc_sr.getAccZ(); 00059 i++; 00060 } 00061 } 00062 00063 void max_sample_rate(int count) 00064 { 00065 int i = 0; 00066 00067 while (i < count) { 00068 acc_sr.getAccX(); 00069 acc_sr.getAccY(); 00070 acc_sr.getAccZ(); 00071 00072 mag_sr.readVal(MAG_OUT_X_MSB); 00073 mag_sr.readVal(MAG_OUT_Y_MSB); 00074 mag_sr.readVal(MAG_OUT_Z_MSB); 00075 00076 lightSensor_sr.read(); 00077 00078 tsi_sr.readPercentage(); 00079 00080 i++; 00081 } 00082 } 00083 /* 00084 int main() { 00085 int t1, t2; 00086 00087 while (true) { 00088 timer_sr.reset(); 00089 00090 // Accelerometer 00091 timer_sr.start(); 00092 t1 = timer_sr.read_ms(); 00093 accelerometer(COUNT); 00094 t2 = timer_sr.read_ms(); 00095 timer_sr.stop(); 00096 pc_sr.printf("Time to sample acceleromter sensor 1000times = %dms\n", t2 - t1); 00097 00098 timer_sr.reset(); 00099 00100 // magnetometer 00101 timer_sr.start(); 00102 t1 = timer_sr.read_ms(); 00103 magnetometer(COUNT); 00104 t2 = timer_sr.read_ms(); 00105 timer_sr.stop(); 00106 pc_sr.printf("Time to sample magnetometer sensor 1000times = %dms\n", t2 - t1); 00107 00108 timer_sr.reset(); 00109 00110 // light 00111 timer_sr.start(); 00112 t1 = timer_sr.read_ms(); 00113 light(COUNT); 00114 t2 = timer_sr.read_ms(); 00115 timer_sr.stop(); 00116 pc_sr.printf("Time to sample light sensor 1000times = %dms\n", t2 - t1); 00117 00118 timer_sr.reset(); 00119 00120 // touch 00121 timer_sr.start(); 00122 t1 = timer_sr.read_ms(); 00123 touch(COUNT); 00124 t2 = timer_sr.read_ms(); 00125 timer_sr.stop(); 00126 pc_sr.printf("Time to sample touch sensor 1000times = %dms\n", t2 - t1); 00127 00128 timer_sr.reset(); 00129 00130 // All 00131 timer_sr.start(); 00132 t1 = timer_sr.read_ms(); 00133 max_sample_rate(COUNT); 00134 t2 = timer_sr.read_ms(); 00135 timer_sr.stop(); 00136 pc_sr.printf("Time to sample all sensors 1000times = %dms\n", t2 - t1); 00137 wait(3); 00138 } 00139 00140 } 00141 */
Generated on Tue Jul 12 2022 21:36:10 by
1.7.2