Sports tracker

Dependencies:   C12832_lcd CMPS03 FatFileSystem GPS MMA7660 mbed

Fork of Data_Read_Write by GUI

main.cpp

Committer:
GBSingh
Date:
2014-05-01
Revision:
1:6a1228b44183
Parent:
0:5934350323b2
Child:
2:775586529d5e

File content as of revision 1:6a1228b44183:

#include "mbed.h"
#include "MSCFileSystem.h"//usb Library
#include "GPS.h"//GPS library
#include "C12832_lcd.h" // LCD screen library
MSCFileSystem fs("usb"); // Mount flash drive under the name "usb"
C12832_LCD lcd;// Local name for the LCD
GPS gps(p9, p10);//pin for RX and TX of the gps
Serial pc(USBTX, USBRX);
BusIn joy(p15,p12,p13,p16);
DigitalIn fire(p14);
int lock = 0;
int lock2 = 0;
int lock3 = 0;
int lock4 = 0;
void run()
{
    while(1) {
        FILE *longd = fopen( "/usb/long.txt", "a");
        FILE *latd = fopen( "/usb/lat.txt","a");
        if(gps.sample()) {
            lcd.cls();//clear LCD for next reading round
            lcd.locate(3,3);//initial LCD location for x component of acceleration
            lcd.printf("long %.2f\n", gps.longitude);//print x to LCD at locate position
            lcd.printf("lang %.2f\n", gps.latitude);//print y to LCD to new locate position
            wait(0.5);
            fprintf(longd,"%.4f\n",gps.longitude);
            fprintf(latd,"%.4f\n",gps.latitude);
        } else {
            lcd.cls();//clear LCD for next reading round
            lcd.locate(3,3);//initial LCD location for x component of acceleration
            lcd.printf("Oh Dear! No lock :(\n");
            fprintf(longd,"%c\n","Oh Dear! No Lock :(");
            //pc.printf("Oh Dear! No lock :(\n");
        }
        fclose(longd);
        fclose(latd);
    }
}
int main()
{
    FILE *set = fopen( "/usb/setup.txt","a");
    while (lock == 0) {
        lcd.locate(3,3);
        lcd.printf("move to postion 1\n");
        if(fire) {
            gps.sample();
            fprintf(set,"%.5f ",gps.longitude);
            fprintf(set,"%.5f\n",gps.latitude);
            lock = 1;
            //else {
            //   lcd.cls();
            //   lcd.printf("No Lock Please try again\n");
            //   lock = 0;
            // }
        }
    }
    while (lock2 == 0) {
        lcd.locate(3,3);
        lcd.printf("move to postion 2\n");
        if(fire) {
            if(gps.sample()) {
                fprintf(set,"%.5f ",gps.longitude);
                fprintf(set,"%.5f\n",gps.latitude);
                lock2 = 1;
            } else {
                lcd.cls();
                lcd.printf("No Lock Please try again\n");
                lock2 = 0;
            }
        }
    }
    while (lock3 == 0) {
        lcd.locate(3,3);
        lcd.printf("move to postion 3\n");
        if(fire) {
            if(gps.sample()) {
                fprintf(set,"%.5f ",gps.longitude);
                fprintf(set,"%.5f\n",gps.latitude);
                lock3 = 1;
            } else {
                lcd.cls();
                lcd.printf("No Lock Please try again\n");
                lock3 = 0;
            }
        }
    }
    while (lock4 == 0) {
        lcd.locate(3,3);
        lcd.printf("move to postion 4\n");
        if(fire) {
            if(gps.sample()) {
                fprintf(set,"%.5f ",gps.longitude);
                fprintf(set,"%.5f\n",gps.latitude);
                lock4 = 1;
            } else {
                lcd.cls();
                lcd.printf("No Lock Please try again\n");
                lock4 = 0;
            }
        }
    }
    run();
}