Jonathan Witherstone / Mbed 2 deprecated Compass

Dependencies:   C12832 CMPS03 FatFileSystemCpp mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "C12832.h"
00003 #include "CMPS03.h"
00004 #include "MSCFileSystem.h"
00005 #define FSNAME "msc"
00006 
00007 MSCFileSystem msc(FSNAME);
00008 
00009 C12832 lcd(p5, p7, p6, p8, p11);
00010 CMPS03 compass(p9, p10, CMPS03_DEFAULT_I2C_ADDRESS);
00011 Serial pc(USBTX, USBRX);
00012 DigitalIn fire(p14);
00013 PwmOut r (p23);
00014 PwmOut g (p24);
00015 PwmOut b (p25);
00016 
00017 int Time=(300); //time for recording in seconds
00018 int sample=1;   //sample rate in seconds
00019 int j;
00020 int z;
00021 
00022 int array[300];
00023 
00024 FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w");
00025 int main() {
00026 DIR *d;
00027 struct dirent *p;
00028 d = opendir("/" FSNAME);
00029 
00030 while(1){    
00031     lcd.locate(0,0); //prints to lcd;
00032     lcd.printf("Power on \nPress buttton to start");
00033     r=1;
00034     g=0;
00035     b=1;
00036     
00037     //printf("i got here2");
00038 
00039     if (fire){
00040         lcd.cls();
00041         for(int j=0;j<Time;j++){
00042             
00043             //set led to orange
00044             r=0;
00045             g=0.43;
00046             b=1;
00047             
00048             lcd.locate(0,0);
00049             lcd.printf("You have been waiting\n %d seconds", (j));
00050             lcd.locate(0,17);
00051             lcd.printf("%d", (compass.readBearing()/10));
00052             array[j]= (compass.readBearing()/10);
00053             wait(sample);
00054             
00055             }       //ends for loop
00056 
00057         for(z=0;z<Time;z++){
00058             printf("%d\t%d\t\n", z, array[z]);
00059             fprintf(fp,"%d\t%d\r\n", z, array[z]);
00060 
00061             }
00062         fclose(fp);
00063         }           //ends if fire
00064         
00065 
00066         main();
00067 
00068         
00069             }       //ends while loop
00070 
00071 }                   //ends program
00072 
00073