Sports tracker
Dependencies: C12832_lcd CMPS03 FatFileSystem GPS MMA7660 mbed
Fork of Data_Read_Write by
Diff: main.cpp
- Revision:
- 1:6a1228b44183
- Parent:
- 0:5934350323b2
- Child:
- 2:775586529d5e
--- a/main.cpp Sun Nov 06 15:45:12 2011 +0000 +++ b/main.cpp Thu May 01 14:25:31 2014 +0000 @@ -1,39 +1,103 @@ #include "mbed.h" -#include "MSCFileSystem.h" - -MSCFileSystem msc("usb"); // Mount flash drive under the name "msc" -Serial pc(USBTX,USBRX); - -int main() { - unsigned char data[120*160]; // Test array of data - - // Fill the data with values - for (int i=0; i<120*160; i++) { - data[i] = 0xAA; // Fill array with data +#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); } - - // Create timers - Timer Write_time, Read_time; - Write_time.start(); - - // Write to local file - FILE *fp = fopen( "/usb/test.txt", "w"); - for (int i=0; i<120*160; i++) { - fprintf(fp, "%c",data[i]); +} +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; + // } + } } - fclose(fp); - - Write_time.stop(); - pc.printf("\n\rTime taken so write array = %f seconds",Write_time.read()); - - Read_time.start(); - // Read from local file - fopen("/usb/test.txt","r"); - // Get data from file and load back into cam - for (int i=0; i<120*160; i++) { - data[i] = fgetc(fp); // Get the next character + 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; + } + } } - fclose(fp); - Read_time.stop(); - pc.printf("\n\rTime taken to read array = %f seconds",Read_time.read()); + 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(); } \ No newline at end of file