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:
- 3:1238aecec770
- Parent:
- 2:bae4b43dc1ef
- Child:
- 4:dd5899b3eb3b
--- a/main.cpp Fri Mar 02 17:36:53 2018 +0000 +++ b/main.cpp Tue Mar 06 14:28:15 2018 +0000 @@ -13,16 +13,36 @@ int main() { pc.printf("starting program\n\r"); + + + /* Prints out registrys + // Use for demo + while(1) { + mpl3115_reg_print(0,0); + } + */ + + //Test is getID returns the correct value and we are getting good readings + pc.printf("\n\r*** MPL3115A2 Pressure/Temperature Sensor Test *** \n\r"); + uint8_t id; + while ((id=pressure_sensor.getID())!=0xC4) { + pc.printf("Status read unsuccessful: Value = 0x%02x\n\r",id); + pc.printf("Check wiring to the pressure sensor\n\r",id); + pc.printf("Retesting for correct ID in 1 second...\n\r"); + wait(1); + } + pc.printf("Status read successfully: Value = 0x%02x\n\r",id); + pc.printf("***1hz readings from the pressure sensor***\n\r"); int i = 0; int arraySize = 1000; double altitudeReading[arraySize]; - + // Set all elements in array to -1, so easier to tell what start values were for (i = 0; i < arraySize; i++) { altitudeReading[i] = -1; } i = 0; while (1) { - if(event.read()) { + if(event.read()) {// if pin A3 has electricy pc.printf("reading an altitude at this point\r\n"); altitudeReading[i] = pressure_sensor.getAltitude(); i++; @@ -30,7 +50,7 @@ i = 0; } } - if (pc.readable()) { + if (pc.readable()) { // check if we need to print everything char c = pc.getc(); pc.printf("we read a char, it was %c\r\n",c); if (c == 'p') { @@ -41,34 +61,9 @@ } } } - wait_ms(500); - } -} - - - /* initial testing used for pressure/Temperture sensor - pc.printf("\n\r*** MPL3115A2 Pressure/Temperature Sensor Test *** \n\r"); - while ((id=pressure_sensor.getID())!=0xC4) { - pc.printf("Status read unsuccessful: Value = 0x%02x\n\r",id); - pc.printf("Check wiring to the pressure sensor\n\r",id); - pc.printf("Retesting for correct ID in 1 second...\n\r"); - wait(1); + wait_ms(500); // Half a minute is spent between each measure } - pc.printf("Status read successfully: Value = 0x%02x\n\r",id); - pc.printf("***1hz readings from the pressure sensor***\n\r"); - // initial testing for pressure/temperature sensor - while(1) { - pc.printf("%f hPA; %f m\n\r",pressure_sensor.getPressure(),pressure_sensor.getAltitude()); - myled = !myled; - wait(1); - } - */ - - /* Prints out registrys - while(1) { - mpl3115_reg_print(0,0); - } - */ +} int mpl3115_reg_print(int start, int length) { int maxLength = 0x2E; @@ -120,6 +115,5 @@ pc.printf("%#04x: %s=%#04x\n\r", i, regNames[i], data); // Print register wait_ms(500); } - return 0; } \ No newline at end of file