as

Dependencies:   C12832 CMPS03 FatFileSystemCpp mbed

Committer:
JWitherstone
Date:
Wed May 07 10:15:01 2014 +0000
Revision:
0:6cf24371ad4f
this is compass;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JWitherstone 0:6cf24371ad4f 1 #include "mbed.h"
JWitherstone 0:6cf24371ad4f 2 #include "C12832.h"
JWitherstone 0:6cf24371ad4f 3 #include "CMPS03.h"
JWitherstone 0:6cf24371ad4f 4 #include "MSCFileSystem.h"
JWitherstone 0:6cf24371ad4f 5 #define FSNAME "msc"
JWitherstone 0:6cf24371ad4f 6
JWitherstone 0:6cf24371ad4f 7 MSCFileSystem msc(FSNAME);
JWitherstone 0:6cf24371ad4f 8
JWitherstone 0:6cf24371ad4f 9 C12832 lcd(p5, p7, p6, p8, p11);
JWitherstone 0:6cf24371ad4f 10 CMPS03 compass(p9, p10, CMPS03_DEFAULT_I2C_ADDRESS);
JWitherstone 0:6cf24371ad4f 11 Serial pc(USBTX, USBRX);
JWitherstone 0:6cf24371ad4f 12 DigitalIn fire(p14);
JWitherstone 0:6cf24371ad4f 13 PwmOut r (p23);
JWitherstone 0:6cf24371ad4f 14 PwmOut g (p24);
JWitherstone 0:6cf24371ad4f 15 PwmOut b (p25);
JWitherstone 0:6cf24371ad4f 16
JWitherstone 0:6cf24371ad4f 17 int Time=(300); //time for recording in seconds
JWitherstone 0:6cf24371ad4f 18 int sample=1; //sample rate in seconds
JWitherstone 0:6cf24371ad4f 19 int j;
JWitherstone 0:6cf24371ad4f 20 int z;
JWitherstone 0:6cf24371ad4f 21
JWitherstone 0:6cf24371ad4f 22 int array[300];
JWitherstone 0:6cf24371ad4f 23
JWitherstone 0:6cf24371ad4f 24 FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w");
JWitherstone 0:6cf24371ad4f 25 int main() {
JWitherstone 0:6cf24371ad4f 26 DIR *d;
JWitherstone 0:6cf24371ad4f 27 struct dirent *p;
JWitherstone 0:6cf24371ad4f 28 d = opendir("/" FSNAME);
JWitherstone 0:6cf24371ad4f 29
JWitherstone 0:6cf24371ad4f 30 while(1){
JWitherstone 0:6cf24371ad4f 31 lcd.locate(0,0); //prints to lcd;
JWitherstone 0:6cf24371ad4f 32 lcd.printf("Power on \nPress buttton to start");
JWitherstone 0:6cf24371ad4f 33 r=1;
JWitherstone 0:6cf24371ad4f 34 g=0;
JWitherstone 0:6cf24371ad4f 35 b=1;
JWitherstone 0:6cf24371ad4f 36
JWitherstone 0:6cf24371ad4f 37 //printf("i got here2");
JWitherstone 0:6cf24371ad4f 38
JWitherstone 0:6cf24371ad4f 39 if (fire){
JWitherstone 0:6cf24371ad4f 40 lcd.cls();
JWitherstone 0:6cf24371ad4f 41 for(int j=0;j<Time;j++){
JWitherstone 0:6cf24371ad4f 42
JWitherstone 0:6cf24371ad4f 43 //set led to orange
JWitherstone 0:6cf24371ad4f 44 r=0;
JWitherstone 0:6cf24371ad4f 45 g=0.43;
JWitherstone 0:6cf24371ad4f 46 b=1;
JWitherstone 0:6cf24371ad4f 47
JWitherstone 0:6cf24371ad4f 48 lcd.locate(0,0);
JWitherstone 0:6cf24371ad4f 49 lcd.printf("You have been waiting\n %d seconds", (j));
JWitherstone 0:6cf24371ad4f 50 lcd.locate(0,17);
JWitherstone 0:6cf24371ad4f 51 lcd.printf("%d", (compass.readBearing()/10));
JWitherstone 0:6cf24371ad4f 52 array[j]= (compass.readBearing()/10);
JWitherstone 0:6cf24371ad4f 53 wait(sample);
JWitherstone 0:6cf24371ad4f 54
JWitherstone 0:6cf24371ad4f 55 } //ends for loop
JWitherstone 0:6cf24371ad4f 56
JWitherstone 0:6cf24371ad4f 57 for(z=0;z<Time;z++){
JWitherstone 0:6cf24371ad4f 58 printf("%d\t%d\t\n", z, array[z]);
JWitherstone 0:6cf24371ad4f 59 fprintf(fp,"%d\t%d\r\n", z, array[z]);
JWitherstone 0:6cf24371ad4f 60
JWitherstone 0:6cf24371ad4f 61 }
JWitherstone 0:6cf24371ad4f 62 fclose(fp);
JWitherstone 0:6cf24371ad4f 63 } //ends if fire
JWitherstone 0:6cf24371ad4f 64
JWitherstone 0:6cf24371ad4f 65
JWitherstone 0:6cf24371ad4f 66 main();
JWitherstone 0:6cf24371ad4f 67
JWitherstone 0:6cf24371ad4f 68
JWitherstone 0:6cf24371ad4f 69 } //ends while loop
JWitherstone 0:6cf24371ad4f 70
JWitherstone 0:6cf24371ad4f 71 } //ends program
JWitherstone 0:6cf24371ad4f 72
JWitherstone 0:6cf24371ad4f 73