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.
Diff: main.cpp
- Revision:
- 2:bae4b43dc1ef
- Parent:
- 1:84b9a3e560fe
- Child:
- 3:1238aecec770
--- a/main.cpp Thu Mar 01 16:04:03 2018 +0000
+++ b/main.cpp Fri Mar 02 17:36:53 2018 +0000
@@ -9,21 +9,21 @@
// Selects SCL on I2C1_SCL on pin PB_6
// The I2C address of the pressure sensor is fixed at 0x60.
MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
-
-
-
-
int mpl3115_reg_print(int start, int length);
-
int main() {
pc.printf("starting program\n\r");
- int i;
- int arraySize = 100;
- double altitudeReading[arraySize];
- while (1) {
- while(event.read()) {
- pc.printf("starting to read\r\n");
+ int i = 0;
+ int arraySize = 1000;
+ double altitudeReading[arraySize];
+
+ for (i = 0; i < arraySize; i++) {
+ altitudeReading[i] = -1;
+ }
+ i = 0;
+ while (1) {
+ if(event.read()) {
+ pc.printf("reading an altitude at this point\r\n");
altitudeReading[i] = pressure_sensor.getAltitude();
i++;
if (i > arraySize) {
@@ -37,10 +37,11 @@
pc.printf("read a p\r\n");
int j = 0;
for (j = 0; j < arraySize; j++) {
- pc.printf("j = %d, altitude = %f\r\n", i, altitudeReading[j]);
+ pc.printf("j = %d, altitude = %f\r\n", j, altitudeReading[j]);
}
}
}
+ wait_ms(500);
}
}
@@ -95,8 +96,7 @@
pc.printf("Error: Unable to read from WHO_AM_I register\n\r");
return -1;
}
-
-
+ // array of names of the registries
char regNames [0x2E][30] = {
"STATUS", "OUT_P_MSB", "OUT_P_CSB",
"OUT_P_LSB", "OUT_T_MSB", "OUT_T_LSB",
@@ -114,6 +114,7 @@
"CTRL_REG2","CTRL_REG3","CTRL_REG4",
"CTRL_REG5", "OFF_P", "OFF_T", "OFF_H"
};
+ // For loop to print out each registry value
for (int i = start; i < end; i++) {
pressure_sensor.readRegs(i,&data,8);
pc.printf("%#04x: %s=%#04x\n\r", i, regNames[i], data); // Print register