This is a repository for code relating to mbed Fitness Tracker

Dependencies:   mbed PulseSensor2 SCP1000 mbed-rtos 4DGL-uLCD-SE LSM9DS1_Library_cal PinDetect FatFileSystemCpp GP-20U7

Files at this revision

API Documentation at this revision

Comitter:
dyu2021
Date:
Wed Apr 22 20:00:57 2020 +0000
Parent:
30:eb4640146f45
Child:
32:cdbd7de8ae10
Commit message:
Replaced everything with working lib and main.cpp

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
GP-20U7.lib Show annotated file Show diff for this revision Revisions of this file
GPS.lib Show diff for this revision Revisions of this file
GT511C3.lib Show diff for this revision Revisions of this file
Pedometer.cpp Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
PulseSensor.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show diff for this revision Revisions of this file
SDcardTest.cpp Show diff for this revision Revisions of this file
data_collection.cpp Show diff for this revision Revisions of this file
fingerprint_scanner.cpp Show diff for this revision Revisions of this file
gps_sensor.cpp Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main_ticker.cpp Show diff for this revision Revisions of this file
maybe_final.cpp Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
pressure_sensor.cpp Show diff for this revision Revisions of this file
pulse_sensor.cpp Show diff for this revision Revisions of this file
--- a/4DGL-uLCD-SE.lib	Wed Apr 22 14:52:37 2020 +0000
+++ b/4DGL-uLCD-SE.lib	Wed Apr 22 20:00:57 2020 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
+https://os.mbed.com/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GP-20U7.lib	Wed Apr 22 20:00:57 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/memig3/code/GP-20U7/#a6214cf7f73b
--- a/GPS.lib	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/memig3/code/GPS/#6a9fa8824e44
--- a/GT511C3.lib	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/tosihisa/code/GT511C3/#90c64cb9db58
--- a/Pedometer.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-#include "mbed.h"
-#include "LSM9DS1.h"
-#include "SCP1000.h"
-#include "MSCFileSystem.h"
-#include "PulseSensor.h"
-#include "PinDetect.h"
-#include "uLCD_4DGL.h"
-
-SCP1000 scp1000(p5,p6,p7,p8);
-LSM9DS1 IMU(p9, p10, 0xD6, 0x3C);
-PulseSensor PPG(p20);
-uLCD_4DGL uLCD(p28,p27,p21);
-Serial pc(USBTX, USBRX);
-DigitalOut myled = LED1;
-AnalogIn pot(p19);
-PinDetect pb(p29);
-
-#define FSNAME "msc"
-MSCFileSystem msc(FSNAME);
-
-volatile int bpm;
-volatile int steps = 0;
-volatile int flights = 0;
-char stat_string[3];
-
-bool run = true;
-// using a ticker to update the LCD so that it doesn't freeze up from constantly 
-// updating
-Ticker LCD;
-
-// when the pushbotton is pressed the run flag is set to false and the main 
-// function while loop exits so that the data file can be closed 
-// so press the button when you're ready to be done collecting data
-void button (void) {
-    run = false;
-}
-
-// Reads the value of the potentiometer and averages over 3 readings to get rid 
-// of random spikes/zero values. Returns either a 1, 2 or 3 based on which 3rd 
-// of its range the potentiometer is in and which screen should be displayed
-int read_pot(void) {
-    float m1; 
-    float m2;
-    float m3;
-    while(1) {
-        m1 = pot.read();
-        m2 = pot.read();
-        m3 = pot.read();
-        if(m1 < 0.33 && m2 < 0.33 && m3 < 0.33) {
-            return 1;
-        }else if(m1 >= 0.33 && m1 < 0.67 && m2 >= 0.33 && m2 < 0.67 && m3 >= 0.33 && m3 < 0.67) {
-            return 2;
-        }else if(m1 >= 0.67 && m2 >= 0.67 && m3 > 0.67) {
-            return 3;
-        }
-    }
-}
-
-// Ticker callback function that updates the LCD screen every 0.1 seconds
-void update_screen(void) {
-    int mode = read_pot();
-    uLCD.locate(1, 2);
-    uLCD.text_width(1);
-    uLCD.text_height(1);
-    uLCD.color(WHITE);
-    switch(mode) {
-        case 1:
-            uLCD.puts("   Heart Rate");
-            if(bpm < 100) {
-                sprintf(stat_string, "%d ", bpm);
-            }else {
-                sprintf(stat_string, "%d", bpm);
-            }
-            break;
-        case 2:
-            uLCD.puts("      Steps    ");
-            if(steps < 10) {
-                sprintf(stat_string, " %d ", steps);
-            }else if(steps < 100) {
-                sprintf(stat_string, "%d ", steps);
-            }else {
-                sprintf(stat_string, "%d", steps);
-            }
-            break;
-        case 3:
-            uLCD.puts("     Flights   ");
-            if(flights < 10) {
-                sprintf(stat_string, " %d ", flights);
-            }else if(flights < 100) {
-                sprintf(stat_string, "%d ", flights);
-            }else {
-                sprintf(stat_string, "%d", flights);
-            }
-            break;
-    }
-    uLCD.locate(2, 2);
-    uLCD.text_width(3);
-    uLCD.text_height(3);
-    uLCD.color(RED);
-    uLCD.puts(stat_string);
-}
-    
-int main() {
-    // Off button
-    pb.mode(PullUp);
-    wait(.01);
-    pb.attach_deasserted(&button);
-    pb.setSampleFrequency();
-    // LCD screen
-    LCD.attach(&update_screen, 0.1);
-    uLCD.baudrate(3000000);
-    // LED indicates whether or not data is being collected
-    myled = 0;
-    // Start sensors
-    int sample_num = 0;
-    PPG.start();
-    IMU.begin();
-    IMU.calibrate(1);
-    float ax;
-    float ay;
-    float az;
-    float mag = 0;
-    float buffer[2] = {0};
-    float avg_buffer[2] = {0};
-    float avg;
-    unsigned long pressure;
-    // Initialize data file on usb flash drive
-    FILE *fp = fopen( "/msc/data.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "sample number, pressure (Pa), ax (Gs), ay (Gs), az (Gs), lowpassed magnitude (Gs), heart rate (bpm)\n");
-    
-    while(run) {
-        // Read Sensors
-        bpm = PPG.get_BPM();
-        pressure = scp1000.readPressure();
-        IMU.readAccel();
-        ax = IMU.calcAccel(IMU.ax);
-        ay = IMU.calcAccel(IMU.ay);
-        az = IMU.calcAccel(IMU.az);
-        // Calculate the 3 point moving average of the magnitude of the 
-        // acceleration vector
-        mag = sqrt((ax*ax) + (ay*ay) + (az*az));
-        avg = (buffer[0] + buffer[1] + mag) / 3;
-        buffer[0] = buffer[1];
-        buffer[1] = mag;
-        // Count a step if the previous point was a maximum (greater than the 
-        // current point and 2 points back) and was greater than the threshold 
-        // value of 1.05
-        if(sample_num > 1) {
-            if((avg_buffer[1] > avg_buffer[0]) && (avg < avg_buffer[1]) && (avg_buffer[1] > 1.05)) {
-                steps++;
-            }
-        }
-        avg_buffer[0] = avg_buffer[1];
-        avg_buffer[1] = avg;
-        // Save the data to the usb flash drive and print to the terminal
-        fprintf(fp, "%d, %lu, %f, %f, %f, %f, %d\r\n", sample_num, pressure, ax, ay, az, avg, bpm); 
-        pc.printf("%d, %lu, %f, %f, %f, %f, %d\r\n", sample_num, pressure, ax, ay, az, avg, bpm); 
-        sample_num++;
-        myled = 1;
-        // Sampling rate of ~200 Hz
-        wait(.005);
-    }
-    fclose(fp);
-    myled = 0;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Wed Apr 22 20:00:57 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AjK/code/PinDetect/#cb3afc45028b
--- a/PulseSensor.lib	Wed Apr 22 14:52:37 2020 +0000
+++ b/PulseSensor.lib	Wed Apr 22 20:00:57 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/memig3/code/PulseSensor/#bb658291fa96
+https://os.mbed.com/users/memig3/code/PulseSensor2/#2d8deec7cae7
--- a/SDFileSystem.lib	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
--- a/SDcardTest.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-
-#include "mbed.h"
-#include "SDFileSystem.h"
- 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
-Serial pc(USBTX,USBRX);
-
-
-float y[100];
-char x[100],z[100];
-
-
-
-int main() { 
-
-
-    FILE *fp = fopen("/sd/text1.txt", "r");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    //fprintf(fp, "Hello fun SD Card World!");
-    for (int i = 0; i<10;i++)
-    {
-    fscanf(fp,"%s\t%f\t%s\r\n",&x[0],&y[i],&z[0]);
-    pc.printf("%s %f %s \r\n",x,y[i],z);
-    }
-    
-    fclose(fp); 
-    
-    
-}
\ No newline at end of file
--- a/data_collection.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-#include "mbed.h"
-#include "LSM9DS1.h"
-#include "SCP1000.h"
-#include "SDFileSystem.h"
-
-SCP1000 scp1000(p5,p6,p7,p8);
-SDFileSystem sd(p11, p12, p13, p26, "sd");
-LSM9DS1 IMU(p28, p27, 0xD6, 0x3C);
-Serial pc(USBTX, USBRX);
-DigitalOut myled = LED1;
-
-int main() {
-    myled = 0;
-    float time = 0;
-    IMU.begin();
-    IMU.calibrate(1);
-    float ax;
-    float ay;
-    float az;
-    //float prevMag = 0;
-    float mag = 0;
-    //float lpValue;
-    //float alpha = 0.5;
-    float buffer[2] = {0};
-    float avg;
-    mkdir("/sd/mydir", 0777);
-    FILE *fp = fopen("/sd/mydir/data.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "time, pressure (Pa), ax (Gs), ay (Gs), az (Gs), lowpassed magnitude (Gs)\n");
-    while(1) {
-        IMU.readAccel();
-        ax = IMU.calcAccel(IMU.ax);
-        ay = IMU.calcAccel(IMU.ay);
-        az = IMU.calcAccel(IMU.az);
-        //prevMag = lpValue;
-        mag = sqrt((ax*ax) + (ay*ay) + (az*az));
-        //lpValue = (alpha * prevMag) + (1 - alpha) * mag;
-        avg = (buffer[0] + buffer[1] + mag) / 3;
-        buffer[0] = buffer[1];
-        buffer[1] = mag;
-        fprintf(fp, "%f, %d, %f, %f, %f, %f\n", time, scp1000.readPressure(), ax, ay, az, avg); 
-        pc.printf("%f, %d, %f, %f, %f, %f\r\n", time, scp1000.readPressure(), ax, ay, az, avg); 
-        time = time + .005;
-        myled = 1;
-        wait(0.005);
-    }
-}
--- a/fingerprint_scanner.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#include "mbed.h"
-#include "GT511C3.hpp"
-
-Serial debug(USBTX,USBRX);
-
-DigitalOut myled(LED1);
-GT511C3 finger(p13,p14);
-
-int progress(int status,char *msg)
-{
-    debug.printf("%s",msg);
-    return 0;
-}
-
-int main() {
-    int sts = 0;
-    int ID = 0;
-
-    debug.format(8,Serial::None,1);
-    debug.baud(115200);
-
-    debug.printf("Fingerprint reader module \"GT-511C3 / GT-511C31\" test program.\n");
-    debug.printf("Build: %s %s\n",__DATE__,__TIME__);
-
-    debug.printf("Open\n");
-    sts = finger.Open();
-    debug.printf("sts = %d\n",sts);
-    if(sts == 0){
-        int i;
-        debug.printf("FirmwareVersion = %lx\n",finger.FirmwareVersion);
-        debug.printf("IsoAreaMaxSize = %ld\n",finger.IsoAreaMaxSize);
-        debug.printf("DeviceSerialNumber = ");
-        for(i = 0; i < sizeof(finger.DeviceSerialNumber);i++){
-            debug.printf("%02X",finger.DeviceSerialNumber[i]);
-        }
-        debug.printf("\n");
-    }
-
-    if(1){
-        int EnrollID = 11;
-        if(finger.CheckEnrolled(EnrollID) == 0){
-            debug.printf("EnrollID(%d) is already enrolled.Delete!\n",EnrollID);
-            if(finger.DeleteID(EnrollID) == 0){
-                debug.printf("Delete OK!\n");
-            }
-        }
-        finger.Enroll(EnrollID,progress);
-    }
-
-    finger.CmosLed(1);
-    while(1) {
-        debug.printf("Press finger for Identify\n");
-        finger.WaitPress(1);
-        if(finger.Capture(1) != 0)
-            continue;
-        ID = finger.Identify();
-        debug.printf("ID = %d\n",ID); 
-        debug.printf("Remove finger\n");
-        finger.WaitPress(0);
-    }
-}
--- a/gps_sensor.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#include "mbed.h"
-#include "GPS.h"
-
-Serial pc(USBTX, USBRX);
-GPS gps(p9, p10);
-
-int main() {
-    while(1) {
-        if(gps.sample()) {
-            pc.printf("Longitude: %f degrees %c\n\rLatitude: %f degrees %c\n\rAltitude: %f meters \n\rUTC time: %f\n\r", gps.longitude, gps.ns, gps.latitude, gps.ew, gps.alt, gps.time);
-        } else {
-            pc.printf("Oh Dear! No lock :(\n\r");
-        }
-    }
-}
\ No newline at end of file
--- a/main.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ b/main.cpp	Wed Apr 22 20:00:57 2020 +0000
@@ -2,10 +2,11 @@
 #include "rtos.h"
 #include "LSM9DS1.h"
 #include "SCP1000.h"
-#include "MSCFileSystem.h"
 #include "PulseSensor.h"
 #include "PinDetect.h"
 #include "uLCD_4DGL.h"
+#include "GPS.h"
+#include "MSCFileSystem.h"
  
 SCP1000 scp1000(p5,p6,p7,p8);
 LSM9DS1 IMU(p9, p10, 0xD6, 0x3C);
@@ -18,39 +19,64 @@
 DigitalOut four = LED4;
 AnalogIn pot(p20);
 PinDetect pb(p21);
- 
+GPS gps(p13, p14);
+
 #define FSNAME "msc"
-MSCFileSystem msc(FSNAME);
+MSCFileSystem msc(FSNAME); 
  
-volatile int bpm;
-volatile int steps = 0;
-volatile int flights = 0;
-volatile float distance = 0.0;
-volatile int calories = 0;
-volatile unsigned long pressure;
+int bpm;
+int steps = 0;
+int flights = 0;
+float distance = 0.0;
+float calories = 0;
+int oldSteps = 0;
+const int stepGoal = 100;
+float stride_length = 0.0;
+
+unsigned long pressure;
+float latitude = 0;
+float longitude = 0;
+float old_lat = 0;
+float old_lon = 0;
+#define PI 3.14159
+unsigned long p_buff[4];
+int count = 0;
+
+int mode = 1;
+int oldMode = 1;
  
-volatile int mode = 1;
-volatile int oldMode = 1;
- 
+bool run = true;
+
+int gender;
+int weight;
+int age;
+int screen = 1;
+int oldScreen = 1;
+bool setup_state = true;
+
+Timer usb_timer;
+
 Thread thread1;
 Thread thread2;
 Thread thread3;
 Thread thread4;
 Thread thread5;
- 
-bool run = true;
-Mutex mtx;
+Mutex serial_mtx;
+Mutex usb_mtx;
  
 // when the pushbotton is pressed the run flag is set to false and the main 
 // function while loop exits so that the data file can be closed 
 // so press the button when you're ready to be done collecting data
 void button (void) {
     run = false;
-    thread1.terminate();
-    thread2.terminate();
-    thread3.terminate();
-    thread4.terminate();
-    thread5.terminate();
+}
+
+void next() {
+    oldScreen = screen;
+    screen++;
+    if(screen == 4) {
+        setup_state = false;
+    }
 }
  
 // Reads the value of the potentiometer and averages over 3 readings to get rid 
@@ -60,36 +86,28 @@
     float m1; 
     float m2;
     float m3;
-    while(1) {
-        oldMode = mode;
-        m1 = pot.read();
-        m2 = pot.read();
-        m3 = pot.read();
-        if(m1 < 0.2 && m2 < 0.2 && m3 < 0.2) {
-            mode = 1;
-        } else if(m1 >= 0.2 && m1 < 0.4 && m2 >= 0.2 && m2 < 0.4 && m3 >= 0.2 && m3 < 0.4) {
-            mode = 2;
-        } else if(m1 >= 0.4 && m1 < 0.6 && m2 >= 0.4 && m2 < 0.6 && m3 >= 0.4 && m3 < 0.6) {
-            mode = 3;
-        } else if(m1 >= 0.6 && m1 < 0.8 && m2 >= 0.6 && m2 < 0.8 && m3 >= 0.6 && m3 < 0.8) {
-            mode = 4;
-        } else if(m1 >= 0.8 && m2 >= 0.8 && m3 >= 0.8) {
-            mode = 5;
-        }
-        //when the mode changes, clear the screen
-        if (oldMode != mode) {
-            mtx.lock();
-            uLCD.filled_rectangle(0,0, 128, 128, BLACK);
-            mtx.unlock();
-        }
-        Thread::wait(200);
+    oldMode = mode;
+    m1 = pot.read();
+    m2 = pot.read();
+    m3 = pot.read();
+    if(m1 < 0.2 && m2 < 0.2 && m3 < 0.2) {
+        mode = 1;
+    } else if(m1 >= 0.2 && m1 < 0.4 && m2 >= 0.2 && m2 < 0.4 && m3 >= 0.2 && m3 < 0.4) {
+        mode = 2;
+    } else if(m1 >= 0.4 && m1 < 0.6 && m2 >= 0.4 && m2 < 0.6 && m3 >= 0.4 && m3 < 0.6) {
+        mode = 3;
+    } else if(m1 >= 0.6 && m1 < 0.8 && m2 >= 0.6 && m2 < 0.8 && m3 >= 0.6 && m3 < 0.8) {
+        mode = 4;
+    } else if(m1 >= 0.8 && m2 >= 0.8 && m3 >= 0.8) {
+        mode = 5;
     }
+    //when the mode changes, clear the screen
 }    
  
 //Display the time on the top
 void display_time() {
     while(1) {
-        mtx.lock();
+        serial_mtx.lock();
         uLCD.locate(1, 1);
         uLCD.color(WHITE);
         uLCD.text_width(2);
@@ -98,44 +116,116 @@
         char timeBuffer[32];
         strftime(timeBuffer, 32, "%I:%M %p\r\n", localtime(&seconds));
         uLCD.printf("%s", timeBuffer);
-        mtx.unlock();
-        Thread::wait(500);
+        serial_mtx.unlock();
+        Thread::wait(700);
+    }
+}
+
+void setup_screen(void) {
+    while(1) {
+        serial_mtx.lock();
+        if (oldScreen != screen) {
+            uLCD.filled_rectangle(0,0, 128, 128, BLACK);
+            oldScreen++;
+        }
+        switch(screen) {
+            case 1:
+                //Gender
+                uLCD.locate(2, 1);
+                uLCD.text_width(2);
+                uLCD.text_height(2);
+                uLCD.puts("Gender");
+                uLCD.text_width(3);
+                uLCD.text_height(3);
+                uLCD.locate(1, 3);
+                uLCD.putc('M');
+                uLCD.locate(4, 3);
+                uLCD.putc('F');
+                if(pot.read() > 0.5) {
+                    gender = 0;
+                    uLCD.rectangle(13, 60, 48, 100, BLACK);
+                    uLCD.rectangle(75, 60, 110, 100, GREEN);
+                } else {
+                    gender = 1;
+                    uLCD.rectangle(75, 60, 110, 100, BLACK);
+                    uLCD.rectangle(13, 60, 48, 100, GREEN);
+                }
+                break;
+            case 2:
+                //Weight
+                uLCD.color(WHITE);
+                uLCD.locate(9, 14);
+                uLCD.text_width(1);
+                uLCD.text_height(1);
+                uLCD.puts("lbs");
+                uLCD.locate(2, 1);
+                uLCD.text_width(2);
+                uLCD.text_height(2);
+                uLCD.puts("Weight");
+                weight = 0.45 * (90 + pot.read() * 210);
+                char weight_string[3];
+                if(weight < 100) {
+                    sprintf(weight_string, " %d", weight);
+                } else {
+                    sprintf(weight_string, "%d", weight);
+                }
+                uLCD.text_width(3);
+                uLCD.text_height(3);
+                uLCD.locate(2, 3);
+                uLCD.color(GREEN);
+                uLCD.puts(weight_string);
+                uLCD.line(35, 100, 110, 100, WHITE);
+                break;
+            case 3:
+                //Age
+                uLCD.color(WHITE);
+                uLCD.locate(3, 1);
+                uLCD.text_width(2);
+                uLCD.text_height(2);
+                uLCD.puts("Age");
+                age = (int) (10 + pot.read() * 89);
+                char age_string[2];
+                sprintf(age_string, "%d", age);
+                uLCD.text_width(3);
+                uLCD.text_height(3);
+                uLCD.locate(2, 3);
+                uLCD.color(GREEN);
+                uLCD.puts(age_string);
+                uLCD.line(40, 100, 90, 100, WHITE);
+                break;
+        }
+        serial_mtx.unlock();
+        Thread::wait(100);
     }
 }
  
-/*
-//Make sure program still alive
-void blink_led() {
+void update_screen(void) {
     while(1) {
-        led2 = !led2;
-        Thread::wait(1000);
-    }
-}  
-*/
- 
-void update_screen(void) {
-        while(1) {
-        mtx.lock();
+        read_pot();
+        serial_mtx.lock();
+        if (oldMode != mode) {
+            uLCD.filled_rectangle(0,0, 128, 128, BLACK);
+        }
         // print the information to the LCD display
         switch(mode) {
             case 1:
                 //Step count
-                uLCD.media_init();
-                uLCD.set_sector_address(0x0000, 0x0005);
-                uLCD.display_image(50, 45);
+                //uLCD.media_init();
+                //uLCD.set_sector_address(0x0000, 0x0005);
+                //uLCD.display_image(50, 45);
                 uLCD.filled_rectangle(10, 110, 118, 115, BLACK);
                 uLCD.locate(3, 11);
                 uLCD.text_height(1);
                 uLCD.text_width(1);
                 uLCD.color(WHITE);
                 uLCD.printf("%4d steps",steps);
-                //uLCD.filled_rectangle(10, 110, 118, 115, WHITE);
+                uLCD.filled_rectangle(10, 110, 10 + int(steps * (110/stepGoal)), 115, WHITE);
                 break;
             case 2:
                 // Heart rate
-                uLCD.media_init();
-                uLCD.set_sector_address(0x0000, 0x000A);
-                uLCD.display_image(50, 45);
+                //uLCD.media_init();
+                //uLCD.set_sector_address(0x0000, 0x000A);
+                //uLCD.display_image(50, 45);
                 uLCD.locate(5, 11);
                 uLCD.text_height(1);
                 uLCD.text_width(1);
@@ -144,31 +234,31 @@
                 break;
             case 3:
                 //Distance
-                uLCD.media_init();
-                uLCD.set_sector_address(0x0000, 0x000F);
-                uLCD.display_image(50, 45);
+                //uLCD.media_init();
+                //uLCD.set_sector_address(0x0000, 0x000F);
+                //uLCD.display_image(50, 45);
                 uLCD.locate(6, 11);
                 uLCD.text_height(1);
                 uLCD.text_width(1);
                 uLCD.color(WHITE);
-                uLCD.printf("%4.2f MI", distance);
+                uLCD.printf("%4.2f ft", distance);
                 break;
             case 4:
                 //Calories
-                uLCD.media_init();
-                uLCD.set_sector_address(0x0000, 0x0000);
-                uLCD.display_image(50, 45);
+                //uLCD.media_init();
+                //uLCD.set_sector_address(0x0000, 0x0000);
+                //uLCD.display_image(50, 45);
                 uLCD.locate(4, 11);
                 uLCD.text_height(1);
                 uLCD.text_width(1);
                 uLCD.color(WHITE);
-                uLCD.printf("%4d cal", calories);
+                uLCD.printf("%4d cal", (int)calories);
                 break;
             case 5:
                 //Floors
-                uLCD.media_init();
-                uLCD.set_sector_address(0x0000, 0x0014);
-                uLCD.display_image(50, 45);
+                //uLCD.media_init();
+                //uLCD.set_sector_address(0x0000, 0x0014);
+                //uLCD.display_image(50, 45);
                 uLCD.locate(4, 11);
                 uLCD.text_height(1);
                 uLCD.text_width(1);
@@ -176,52 +266,127 @@
                 uLCD.printf("%2d floors", flights);
                 break;
         }
-        mtx.unlock();
+        serial_mtx.unlock();
         Thread::wait(100);
     }
 }
- 
-//Read heart rate sensor, only want to read it if in heart rate mode
-void read_heartRate() {
-    while(mode == 2 && run) {
+
+void readHR(){
+    while(1) {
         bpm = PPG.get_BPM();
-        Thread::wait(400);
+        //calories = calories + (.0083)*.239*(gender*(-55.0969+.6309*bpm+.1988*weight+.2017*age)+(1-gender)*(-20.4022+.4472*bpm-.1263*weight+.074*age));
+        calories = calories + (.0083)*0.239*(gender*(-55.0969+.6309*bpm+.1988*0.453592*weight
+                                             +.2017*age)+(1-gender)*(-20.4022+.4472*bpm-.1263*0.453592*weight+.074*age));
+        //converted weight from lbs to kilograms
+
+        //Alternate way to calculate distance (likely more accurate)
+        //distance = distance + (steps - oldSteps)* stride_length;
+        //oldSteps = steps;
+        Thread::wait(500);
     }
 }
- 
-//Read barometer and count floors
-void read_barometer() {
-    unsigned long pressure_buff[10] = {0};
-    while(run) {
+
+void readBarometer()
+{
+    while(1) {
         pressure = scp1000.readPressure();
-        //Floor counting algo here
-        /*if(pressure != 0 && pressure_buff[0] != 0 && pressure - pressure_buff[0] > 100) {
-            flights++;
+        if(count >= 0) count--;
+        unsigned long dif;
+        if(pressure < p_buff[0]) {
+            dif = p_buff[0] - pressure;
+        } else {
+            dif = 0;
         }
-        for(int i = 0; i < (sizeof pressure_buff) - 1; i++) {
-            pressure_buff[i] = pressure_buff[i + 1];
+        if(pressure != 0 && p_buff[0] != 0 && dif > 40 && dif < 60 && count < 0) {
+            flights++;
+            count = 2;
         }
-        pressure_buff[9] = pressure;*/
-        Thread::wait(200);
+        p_buff[0] = p_buff[1];
+        p_buff[1] = p_buff[2];
+        p_buff[2] = p_buff[3];
+        p_buff[3] = pressure;
+        Thread::wait(2000);
     }
 }
         
+void readGPS(){
+    while(1) {
+        serial_mtx.lock();
+        if(gps.connected()) {
+            if(gps.sample()) {
+                if(gps.ns == 'S') {
+                    longitude = gps.longitude*PI/180;
+                } else {
+                    longitude = -gps.longitude*PI/180;
+                }
+                if(gps.ew == 'W') {
+                    latitude = gps.latitude*PI/180;
+                } else {
+                    latitude = -gps.latitude*PI/180;
+                }
+                if(latitude != 0 && longitude != 0 && old_lat != 0 && old_lon != 0) {
+                    float a = sinf(old_lat)*sinf(latitude)+cosf(old_lat)*cosf(latitude)*cosf(longitude-old_lon);
+                    if(a > 1) a = 1;
+                    distance = distance + (.75*acosf(a));
+                }
+                old_lat = latitude;
+                old_lon = longitude;
+                //pc.printf("%f, %f, %f\r\n", latitude, longitude, distance);
+            }
+        }
+        serial_mtx.unlock();
+        Thread::wait(10000);
+    }
+}
+
+void saveData() {
+    // Save the data to the usb flash drive and print to the terminal
+    FILE *fp = fopen( "/msc/data.txt", "a");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+    time_t seconds = time(NULL);
+    char date[32];
+    strftime(date, 32, "%m/%d/%y", localtime(&seconds));
+    fprintf(fp, "%s\t%d\t%d\t%0.2f\t%0.2f\n\r", date, steps, flights, calories, distance);
+    pc.printf("%s\t%d\t%d\t%0.2f\t%0.2f\n\r", date, steps, flights, calories, distance);
+    fclose(fp);
+}
+
+    
 int main() {
-    // Off button
+    //Set RTC time
+    set_time(1256729737);
+    
+    // Next screen button
     pb.mode(PullUp);
-    pb.attach_deasserted(&button);
+    pb.attach_deasserted(&next);
     pb.setSampleFrequency();
     
-    // set up the display
+    //set up the display
     uLCD.baudrate(3000000);
     uLCD.background_color(BLACK);
     uLCD.cls();
+    thread1.start(setup_screen);
     
-    //Set RTC time
-    set_time(1256729737);
+    while(setup_state) {
+        pc.printf("%d\r\n", screen);
+    }
+    thread1.terminate();
+    
+    // Off button
+    pb.attach_deasserted(&button);
+    
+    // set up the display
+    uLCD.cls();
+    thread1.start(update_screen);
+    thread2.start(display_time);
     
     // LED indicates whether or not data is being collected
     one = 0;
+    two = 0;
+    three = 0;
+    four = 0;
     // Start sensors
     int sample_num = 1;
     PPG.start();
@@ -236,23 +401,29 @@
     float avg;
     
     // Initialize data file on usb flash drive
-    FILE *fp = fopen( "/msc/data.txt", "w");
+    usb_mtx.lock();
+    FILE *fp = fopen( "/msc/data.txt", "r+");
     if(fp == NULL) {
         error("Could not open file for write\n");
     }
-    fprintf(fp, "Sample Number, Pressure (Pa), Acceleration Magnitude (Gs), Heart Rate (bpm)\n");
+    //Check to see if file is empty, not working right now
+    fseek (fp, 0, SEEK_END);
+    int size = ftell(fp);
+    if (0 == size) {
+        fprintf(fp, "Date\tSteps\tFloors\tCalories\tDistance (ft)\r\n");
+        pc.printf("Data.txt rewritten\r\n");
+    }
+    fclose(fp);
+    usb_mtx.unlock();
     
-    //Start threads
-    thread1.start(update_screen);
-    thread2.start(display_time);
-    thread3.start(read_pot);
-    thread4.start(read_heartRate);
-    thread5.start(read_barometer);
-    
+    thread3.start(readBarometer);
+    thread4.start(readGPS);
+    thread5.start(readHR);
+
+    usb_timer.start();
+
     while(run) {
         // Read Sensors
-        //bpm = PPG.get_BPM();
-        //pressure = scp1000.readPressure();
         IMU.readAccel();
         ax = IMU.calcAccel(IMU.ax);
         ay = IMU.calcAccel(IMU.ay);
@@ -269,7 +440,7 @@
         if(sample_num > 1) {
             float dif1 = avg_buffer[1] - avg_buffer[0];
             float dif2 = avg_buffer[1] - avg;
-            float peak_prominence = 0.03;
+            float peak_prominence = 0.01;
             if(dif1 > peak_prominence && dif2 > peak_prominence) {
                 steps++;
             }
@@ -277,14 +448,19 @@
         avg_buffer[0] = avg_buffer[1];
         avg_buffer[1] = avg;
         
-        // Save the data to the usb flash drive and print to the terminal
-        fprintf(fp, "%d, %lu, %f, %d\r\n", sample_num, pressure, avg, bpm); 
-        pc.printf("%d, %lu, %f, %d\r\n", sample_num, pressure, avg, bpm); 
         sample_num++;
         one = !one;
         // Sampling rate of ~200 Hz
-        Thread::wait(50);
+        if(usb_timer.read() >= 30) {
+            //pc.printf("Starting USB Write\r\n");
+            usb_mtx.lock();
+            saveData();
+            usb_mtx.unlock();
+            usb_timer.stop();
+            usb_timer.reset();
+            usb_timer.start();
+        }
+        Thread::wait(200);
     }
-    fclose(fp);
     one = 0;
 }
\ No newline at end of file
--- a/main_ticker.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-#include "mbed.h"
-#include "LSM9DS1.h"
-#include "SCP1000.h"
-#include "PulseSensor.h"
-#include "PinDetect.h"
-#include "uLCD_4DGL.h"
-#include "GPS.h"
-#include "MSCFileSystem.h"
- 
-SCP1000 scp1000(p5,p6,p7,p8);
-LSM9DS1 IMU(p9, p10, 0xD6, 0x3C);
-PulseSensor PPG(p17);
-uLCD_4DGL uLCD(p28,p27,p29);
-Serial pc(USBTX, USBRX);
-DigitalOut one = LED1;
-DigitalOut two = LED2;
-DigitalOut three = LED3;
-DigitalOut four = LED4;
-AnalogIn pot(p20);
-PinDetect pb(p21);
-GPS gps(p13, p14);
-
-#define FSNAME "msc"
-MSCFileSystem msc(FSNAME); 
-
-Ticker display;
-Ticker LCD_clock;
-Ticker Barometer;
-Ticker GPS;
- 
-int bpm;
-int steps = 0;
-int flights = 0;
-float distance = 0.0;
-int calories = 0;
-
-unsigned long pressure;
-float latitude = 0;
-float longitude = 0;
-unsigned long p_buff[4];
-int count = 0;
-
-int mode = 1;
-int oldMode = 1;
- 
-bool run = true;
- 
-// when the pushbotton is pressed the run flag is set to false and the main 
-// function while loop exits so that the data file can be closed 
-// so press the button when you're ready to be done collecting data
-void button (void) {
-    run = false;
-}
- 
-// Reads the value of the potentiometer and averages over 3 readings to get rid 
-// of random spikes/zero values. Returns either a 1, 2 or 3 based on which 3rd 
-// of its range the potentiometer is in and which screen should be displayed
-void read_pot() {
-    float m1; 
-    float m2;
-    float m3;
-    oldMode = mode;
-    m1 = pot.read();
-    m2 = pot.read();
-    m3 = pot.read();
-    if(m1 < 0.2 && m2 < 0.2 && m3 < 0.2) {
-        mode = 1;
-    } else if(m1 >= 0.2 && m1 < 0.4 && m2 >= 0.2 && m2 < 0.4 && m3 >= 0.2 && m3 < 0.4) {
-        mode = 2;
-    } else if(m1 >= 0.4 && m1 < 0.6 && m2 >= 0.4 && m2 < 0.6 && m3 >= 0.4 && m3 < 0.6) {
-        mode = 3;
-    } else if(m1 >= 0.6 && m1 < 0.8 && m2 >= 0.6 && m2 < 0.8 && m3 >= 0.6 && m3 < 0.8) {
-        mode = 4;
-    } else if(m1 >= 0.8 && m2 >= 0.8 && m3 >= 0.8) {
-        mode = 5;
-    }
-    //when the mode changes, clear the screen
-}    
- 
-//Display the time on the top
-void display_time() {
-    uLCD.locate(1, 1);
-    uLCD.color(WHITE);
-    uLCD.text_width(2);
-    uLCD.text_height(3);
-    time_t seconds = time(NULL);
-    char timeBuffer[32];
-    strftime(timeBuffer, 32, "%I:%M %p\r\n", localtime(&seconds));
-    uLCD.printf("%s", timeBuffer);
-}
- 
-void update_screen(void) {
-    read_pot();
-    if (oldMode != mode) {
-        uLCD.filled_rectangle(0,0, 128, 128, BLACK);
-    }
-    // print the information to the LCD display
-    switch(mode) {
-        case 1:
-            //Step count
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0005);
-            uLCD.display_image(50, 45);
-            uLCD.filled_rectangle(10, 110, 118, 115, BLACK);
-            uLCD.locate(3, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4d steps",steps);
-            //uLCD.filled_rectangle(10, 110, 118, 115, WHITE);
-            break;
-        case 2:
-            // Heart rate
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x000A);
-            uLCD.display_image(50, 45);
-            uLCD.locate(5, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%3d BPM", bpm);
-            break;
-        case 3:
-            //Distance
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x000F);
-            uLCD.display_image(50, 45);
-            uLCD.locate(6, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4.2f MI", distance);
-            break;
-        case 4:
-            //Calories
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0000);
-            uLCD.display_image(50, 45);
-            uLCD.locate(4, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4d cal", calories);
-            break;
-        case 5:
-            //Floors
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0014);
-            uLCD.display_image(50, 45);
-            uLCD.locate(4, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%2d floors", flights);
-            break;
-    }
-}
-
-void readBarometer(){
-    pressure = scp1000.readPressure();
-    if(count >= 0) count--;
-    unsigned long dif;
-    if(pressure < p_buff[0]) {
-        dif = p_buff[0] - pressure;
-    }else {
-        dif = 0;
-    }
-    if(pressure != 0 && p_buff[0] != 0 && dif > 40 && dif < 60 && count < 0) {
-        flights++;
-        count = 2;
-    }
-    p_buff[0] = p_buff[1];
-    p_buff[1] = p_buff[2];
-    p_buff[2] = p_buff[3];
-    p_buff[3] = pressure; 
-}
-        
-void readGPS(){
-    if(gps.connected()) {
-        if(gps.sample()) {
-            if(gps.ns == 'S') {
-                longitude = gps.longitude;
-            }else {
-                longitude = -gps.longitude;
-            }
-            if(gps.ew == 'W') {
-                latitude = gps.latitude;
-            }else {
-                latitude = -gps.latitude;
-            }
-        }
-    }
-}
-    
-int main() {
-    // Off button
-    pb.mode(PullUp);
-    pb.attach_deasserted(&button);
-    pb.setSampleFrequency();
-    
-    // set up the display
-    uLCD.baudrate(3000000);
-    uLCD.background_color(BLACK);
-    uLCD.cls();
-    display.attach(&update_screen, 0.5);
-    LCD_clock.attach(&display_time, 0.7);
-    
-    //Set RTC time
-    set_time(1256729737);
-    
-    // LED indicates whether or not data is being collected
-    one = 0;
-    two = 0;
-    three = 0;
-    four = 0;
-    // Start sensors
-    int sample_num = 1;
-    PPG.start();
-    IMU.begin();
-    IMU.calibrate(1);
-    float ax;
-    float ay;
-    float az;
-    float mag = 0;
-    float buffer[2] = {0};
-    float avg_buffer[2] = {0};
-    float avg;
-    
-    // Initialize data file on usb flash drive
-    FILE *fp = fopen( "/msc/data.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Sample Number, Pressure (Pa), Acceleration Magnitude (Gs), Heart Rate (bpm), Latitude (degrees), Longitude (degrees)\n");
-    
-    Barometer.attach(&readBarometer, 2);
-    GPS.attach(&readGPS, 5);
-    
-    while(run) {
-        // Read Sensors
-        
-        bpm = PPG.get_BPM();
-        IMU.readAccel();
-        ax = IMU.calcAccel(IMU.ax);
-        ay = IMU.calcAccel(IMU.ay);
-        az = IMU.calcAccel(IMU.az);
-        // Calculate the 3 point moving average of the magnitude of the 
-        // acceleration vector
-        mag = sqrt((ax*ax) + (ay*ay) + (az*az));
-        avg = (buffer[0] + buffer[1] + mag) / 3;
-        buffer[0] = buffer[1];
-        buffer[1] = mag;
-        // Count a step if the previous point was a maximum (greater than the 
-        // current point and 2 points back) and was greater than the threshold 
-        // value of 1.05
-        if(sample_num > 1) {
-            float dif1 = avg_buffer[1] - avg_buffer[0];
-            float dif2 = avg_buffer[1] - avg;
-            float peak_prominence = 0.03;
-            if(dif1 > peak_prominence && dif2 > peak_prominence) {
-                steps++;
-            }
-        }
-        avg_buffer[0] = avg_buffer[1];
-        avg_buffer[1] = avg;
-        
-        // Save the data to the usb flash drive and print to the terminal
-        //fprintf(fp, "%d, %lu, %f, %d, %f, %f\r\n", sample_num, pressure, avg, bpm, latitude, longitude); 
-        //pc.printf("%d, %lu, %f, %d, %f, %f\r\n", sample_num, pressure, avg, bpm, latitude, longitude); 
-        sample_num++;
-        one = !one;
-        // Sampling rate of ~200 Hz
-        wait(0.2);
-    }
-    fclose(fp);
-    one = 0;
-}
\ No newline at end of file
--- a/maybe_final.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,414 +0,0 @@
-#include "mbed.h"
-#include "LSM9DS1.h"
-#include "SCP1000.h"
-#include "PulseSensor.h"
-#include "PinDetect.h"
-#include "uLCD_4DGL.h"
-#include "GPS.h"
-#include "MSCFileSystem.h"
- 
-SCP1000 scp1000(p5,p6,p7,p8);
-LSM9DS1 IMU(p9, p10, 0xD6, 0x3C);
-PulseSensor PPG(p17);
-uLCD_4DGL uLCD(p28,p27,p29);
-Serial pc(USBTX, USBRX);
-DigitalOut one = LED1;
-DigitalOut two = LED2;
-DigitalOut three = LED3;
-DigitalOut four = LED4;
-AnalogIn pot(p20);
-PinDetect pb(p21);
-GPS gps(p13, p14);
-
-//#define FSNAME "msc"
-//MSCFileSystem msc(FSNAME); 
-
-Ticker display;
-Ticker LCD_clock;
-Ticker Barometer;
-Ticker GPS;
-Ticker HR;
-Ticker setup;
- 
-int bpm;
-int steps = 0;
-int flights = 0;
-float distance = 0.0;
-float calories = 0;
-int oldSteps = 0;
-const int stepGoal = 100;
-float stride_length = 0.0;
-
-unsigned long pressure;
-float latitude = 0;
-float longitude = 0;
-float old_lat = 0;
-float old_lon = 0;
-#define PI 3.14159
-unsigned long p_buff[4];
-int count = 0;
-
-int mode = 1;
-int oldMode = 1;
- 
-bool run = true;
-
-int gender;
-int weight;
-int age;
-int screen = 1;
-int oldScreen = 1;
-bool setup_state = true;
- 
-// when the pushbotton is pressed the run flag is set to false and the main 
-// function while loop exits so that the data file can be closed 
-// so press the button when you're ready to be done collecting data
-void button (void) {
-    run = false;
-}
-
-void next() {
-    oldScreen = screen;
-    screen++;
-    if(screen == 4) {
-        setup_state = false;
-    }
-}
- 
-// Reads the value of the potentiometer and averages over 3 readings to get rid 
-// of random spikes/zero values. Returns either a 1, 2 or 3 based on which 3rd 
-// of its range the potentiometer is in and which screen should be displayed
-void read_pot() {
-    float m1; 
-    float m2;
-    float m3;
-    oldMode = mode;
-    m1 = pot.read();
-    m2 = pot.read();
-    m3 = pot.read();
-    if(m1 < 0.2 && m2 < 0.2 && m3 < 0.2) {
-        mode = 1;
-    } else if(m1 >= 0.2 && m1 < 0.4 && m2 >= 0.2 && m2 < 0.4 && m3 >= 0.2 && m3 < 0.4) {
-        mode = 2;
-    } else if(m1 >= 0.4 && m1 < 0.6 && m2 >= 0.4 && m2 < 0.6 && m3 >= 0.4 && m3 < 0.6) {
-        mode = 3;
-    } else if(m1 >= 0.6 && m1 < 0.8 && m2 >= 0.6 && m2 < 0.8 && m3 >= 0.6 && m3 < 0.8) {
-        mode = 4;
-    } else if(m1 >= 0.8 && m2 >= 0.8 && m3 >= 0.8) {
-        mode = 5;
-    }
-    //when the mode changes, clear the screen
-}    
- 
-//Display the time on the top
-void display_time() {
-    uLCD.locate(1, 1);
-    uLCD.color(WHITE);
-    uLCD.text_width(2);
-    uLCD.text_height(3);
-    time_t seconds = time(NULL);
-    char timeBuffer[32];
-    strftime(timeBuffer, 32, "%I:%M %p\r\n", localtime(&seconds));
-    uLCD.printf("%s", timeBuffer);
-}
-
-void setup_screen(void) {
-    if (oldScreen != screen) {
-        uLCD.filled_rectangle(0,0, 128, 128, BLACK);
-        oldScreen++;
-    }
-    switch(screen) {
-        case 1:
-            //Gender
-            uLCD.locate(2, 1);
-            uLCD.text_width(2);
-            uLCD.text_height(2);
-            uLCD.puts("Gender");
-            uLCD.text_width(3);
-            uLCD.text_height(3);
-            uLCD.locate(1, 3);
-            uLCD.putc('M');
-            uLCD.locate(4, 3);
-            uLCD.putc('F');
-            if(pot.read() > 0.5) {
-                gender = 0;
-                uLCD.rectangle(13, 60, 48, 100, BLACK);
-                uLCD.rectangle(75, 60, 110, 100, GREEN);
-            }else {
-                gender = 1;
-                uLCD.rectangle(75, 60, 110, 100, BLACK);
-                uLCD.rectangle(13, 60, 48, 100, GREEN);
-            }
-            break;
-        case 2: 
-            //Weight
-            uLCD.color(WHITE);
-            uLCD.locate(9, 14);
-            uLCD.text_width(1);
-            uLCD.text_height(1);
-            uLCD.puts("lbs");
-            uLCD.locate(2, 1);
-            uLCD.text_width(2);
-            uLCD.text_height(2);
-            uLCD.puts("Weight");
-            weight = 0.45 * (90 + pot.read() * 210);
-            char weight_string[3];
-            if(weight < 100) {
-                sprintf(weight_string, " %d", weight);
-            }else {
-                sprintf(weight_string, "%d", weight);
-            }
-            uLCD.text_width(3);
-            uLCD.text_height(3);
-            uLCD.locate(2, 3);
-            uLCD.color(GREEN);
-            uLCD.puts(weight_string);
-            uLCD.line(35, 100, 110, 100, WHITE);
-            break;
-        case 3:
-            //Age 
-            uLCD.color(WHITE);
-            uLCD.locate(3, 1);
-            uLCD.text_width(2);
-            uLCD.text_height(2);
-            uLCD.puts("Age");
-            age = (int) (10 + pot.read() * 89);
-            char age_string[2];
-            sprintf(age_string, "%d", age);
-            uLCD.text_width(3);
-            uLCD.text_height(3);
-            uLCD.locate(2, 3);
-            uLCD.color(GREEN);
-            uLCD.puts(age_string);
-            uLCD.line(40, 100, 90, 100, WHITE);
-            break;
-    }
-}
- 
-void update_screen(void) {
-    read_pot();
-    if (oldMode != mode) {
-        uLCD.filled_rectangle(0,0, 128, 128, BLACK);
-    }
-    // print the information to the LCD display
-    switch(mode) {
-        case 1:
-            //Step count
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0005);
-            uLCD.display_image(50, 45);
-            uLCD.filled_rectangle(10, 110, 118, 115, BLACK);
-            uLCD.locate(3, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4d steps",steps);
-            uLCD.filled_rectangle(10, 110, 10 + int(steps * (110/stepGoal)), 115, WHITE);
-            break;
-        case 2:
-            // Heart rate
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x000A);
-            uLCD.display_image(50, 45);
-            uLCD.locate(5, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%3d BPM", bpm);
-            break;
-        case 3:
-            //Distance
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x000F);
-            uLCD.display_image(50, 45);
-            uLCD.locate(5, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4.0f ft", distance);
-            break;
-        case 4:
-            //Calories
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0000);
-            uLCD.display_image(50, 45);
-            uLCD.locate(4, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%4d cal", (int)calories);
-            break;
-        case 5:
-            //Floors
-            uLCD.media_init();
-            uLCD.set_sector_address(0x0000, 0x0014);
-            uLCD.display_image(50, 45);
-            uLCD.locate(4, 11);
-            uLCD.text_height(1);
-            uLCD.text_width(1);
-            uLCD.color(WHITE);
-            uLCD.printf("%2d floors", flights);
-            break;
-    }
-}
-
-void readHR(){
-    bpm = PPG.get_BPM();
-    //calories = calories + (.0083)*.239*(gender*(-55.0969+.6309*bpm+.1988*weight+.2017*age)+(1-gender)*(-20.4022+.4472*bpm-.1263*weight+.074*age));
-    calories = calories + (.0083)*0.239*(gender*(-55.0969+.6309*bpm+.1988*0.453592*weight
-        +.2017*age)+(1-gender)*(-20.4022+.4472*bpm-.1263*0.453592*weight+.074*age));
-    //converted weight from lbs to kilograms
-    
-    //Alternate way to calculate distance (likely more accurate)
-    //distance = distance + (steps - oldSteps)* stride_length;
-    //oldSteps = steps;
-}
-
-void readBarometer(){
-    pressure = scp1000.readPressure();
-    if(count >= 0) count--;
-    unsigned long dif;
-    if(pressure < p_buff[0]) {
-        dif = p_buff[0] - pressure;
-    }else {
-        dif = 0;
-    }
-    if(pressure != 0 && p_buff[0] != 0 && dif > 40 && dif < 60 && count < 0) {
-        flights++;
-        count = 2;
-    }
-    p_buff[0] = p_buff[1];
-    p_buff[1] = p_buff[2];
-    p_buff[2] = p_buff[3];
-    p_buff[3] = pressure; 
-}
-        
-void readGPS(){
-    if(gps.connected()) {
-        if(gps.sample()) {
-            if(gps.ns == 'S') {
-                longitude = gps.longitude*PI/180;
-            }else {
-                longitude = -gps.longitude*PI/180;
-            }
-            if(gps.ew == 'W') {
-                latitude = gps.latitude*PI/180;
-            }else {
-                latitude = -gps.latitude*PI/180;
-            }
-            if(latitude != 0 && longitude != 0 && old_lat != 0 && old_lon != 0) {
-                distance = distance + (3963*acosf(sinf(old_lat)*sinf(latitude)+cosf(old_lat)*cosf(latitude)*cosf(longitude-old_lon)));
-            }
-            old_lat = latitude;
-            old_lon = longitude;
-            //pc.printf("%f, %f, %f\r\n", latitude, longitude, distance);
-        }
-    }
-}
-    
-int main() {
-    //Set RTC time
-    set_time(1256729737);
-    
-    // Next screen button
-    pb.mode(PullUp);
-    pb.attach_deasserted(&next);
-    pb.setSampleFrequency();
-    
-    //set up the display
-    uLCD.baudrate(3000000);
-    uLCD.background_color(BLACK);
-    uLCD.cls();
-    setup.attach(&setup_screen, 0.3);
-    
-    while(setup_state) {
-        pc.printf("%d", screen);
-    }
-    
-    // Off button
-    pb.attach_deasserted(&button);
-    
-    // set up the display
-    setup.detach();
-    uLCD.cls();
-    display.attach(&update_screen, 0.5);
-    LCD_clock.attach(&display_time, 0.7);
-    
-    // LED indicates whether or not data is being collected
-    one = 0;
-    two = 0;
-    three = 0;
-    four = 0;
-    // Start sensors
-    int sample_num = 1;
-    PPG.start();
-    IMU.begin();
-    IMU.calibrate(1);
-    float ax;
-    float ay;
-    float az;
-    float mag = 0;
-    float buffer[2] = {0};
-    float avg_buffer[2] = {0};
-    float avg;
-    float max = 1.0;
-    float min = 1.0;
-    float const K = 0.55;
-    
-    // Initialize data file on usb flash drive
-    /*FILE *fp = fopen( "/msc/data.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Sample Number, Pressure (Pa), Acceleration Magnitude (Gs), Heart Rate (bpm), Latitude (degrees), Longitude (degrees)\n");
-    */
-    
-    Barometer.attach(&readBarometer, 2);
-    GPS.attach(&readGPS, 10);
-    HR.attach(&readHR, 0.5);
-
-    while(run) {
-        // Read Sensors
-        //bpm = PPG.get_BPM();
-        IMU.readAccel();
-        ax = IMU.calcAccel(IMU.ax);
-        ay = IMU.calcAccel(IMU.ay);
-        az = IMU.calcAccel(IMU.az);
-        // Calculate the 3 point moving average of the magnitude of the 
-        // acceleration vector
-        mag = sqrt((ax*ax) + (ay*ay) + (az*az));
-        avg = (buffer[0] + buffer[1] + mag) / 3;
-        buffer[0] = buffer[1];
-        buffer[1] = mag;
-        // Count a step if the previous point was a maximum (greater than the 
-        // current point and 2 points back) and was greater than the threshold 
-        // value of 1.05
-        if(sample_num > 1) {
-            float dif1 = avg_buffer[1] - avg_buffer[0];
-            float dif2 = avg_buffer[1] - avg;
-            float peak_prominence = 0.01;
-            if(dif1 > peak_prominence && dif2 > peak_prominence) {
-                steps++;
-                //https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6412957/
-                stride_length = K * pow((double)(max - min), 0.25) * 3.28084; //feet
-                max = 1.0;
-                min = 1.0;
-            }
-        }
-        if (az > max) { max = az;}
-        else if (az < min) {min = az;}
-        
-        avg_buffer[0] = avg_buffer[1];
-        avg_buffer[1] = avg;
-        
-        // Save the data to the usb flash drive and print to the terminal
-        //fprintf(fp, "%d, %lu, %f, %d, %f, %f\r\n", sample_num, pressure, avg, bpm, latitude, longitude); 
-        //pc.printf("%d, %lu, %f, %d, %f, %f\r\n", sample_num, pressure, avg, bpm, latitude, longitude); 
-        sample_num++;
-        one = !one;
-        // Sampling rate of ~200 Hz
-        wait(0.2);
-    }
-    //fclose(fp);
-    one = 0;
-}
\ No newline at end of file
--- a/mbed-rtos.lib	Wed Apr 22 14:52:37 2020 +0000
+++ b/mbed-rtos.lib	Wed Apr 22 20:00:57 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706
+https://os.mbed.com/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld	Wed Apr 22 14:52:37 2020 +0000
+++ b/mbed.bld	Wed Apr 22 20:00:57 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file
--- a/pressure_sensor.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#include "mbed.h"
-#include "SCP1000.h"
-
-Serial pc(USBTX, USBRX);
-SCP1000 scp1000(p5,p6,p7,p8);
-
-int main() {
-    while(1) {
-        pc.printf("The pressure is %d Pa and the temperature is %f C\r\n", scp1000.readPressure(), scp1000.readTemperature());
-    }
-}
\ No newline at end of file
--- a/pulse_sensor.cpp	Wed Apr 22 14:52:37 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#include "mbed.h"
-#include "PulseSensor.h"
-#include "uLCD_4DGL.h"
- 
-Serial pc(USBTX, USBRX);
-uLCD_4DGL uLCD(p28,p27,p19);
-
-int bpm;
-char bpm_string[3];
-
-void sendDataToProcessing(char symbol, int data)
-{
-    pc.printf("%c%d\r\n", symbol, data);
-}
-
-int main() {
-    uLCD.text_width(3);
-    uLCD.text_height(3);
-    uLCD.color(RED);
-    pc.baud(115200);
-    PulseSensor sensor(p20, sendDataToProcessing);
-    sensor.start();
- 
-    while(1) {
-        bpm = sensor.get_BPM();
-        if(bpm < 100) {
-            sprintf(bpm_string, "%d ", bpm);
-        }else {
-            sprintf(bpm_string, "%d", bpm);
-        }
-        uLCD.locate(2, 2);
-        uLCD.puts(bpm_string);
-    }
-}
\ No newline at end of file