time diffrence betwwen interupts

Dependencies:   mbed-os sd-driver_compatible_with_MAX32630FTHR

Committer:
muigaijosphat
Date:
Thu Jun 13 12:35:14 2019 +0000
Revision:
1:ecf216fbee90
Parent:
0:b7d9a60d3d44
new changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
muigaijosphat 0:b7d9a60d3d44 1 #include "mbed.h"
muigaijosphat 1:ecf216fbee90 2 #include "SDBlockDevice.h"
muigaijosphat 1:ecf216fbee90 3 #include "FATFileSystem.h"
muigaijosphat 1:ecf216fbee90 4 //#include "stdio.h"
muigaijosphat 1:ecf216fbee90 5 //SDBlockDevice sd(PC_12, PC_11, PC_10, D10);
muigaijosphat 1:ecf216fbee90 6 SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
muigaijosphat 1:ecf216fbee90 7 InterruptIn motion_sensor(D6); //motin trigger
muigaijosphat 1:ecf216fbee90 8 DigitalIn myinput(D6); //motion sensor
muigaijosphat 1:ecf216fbee90 9
muigaijosphat 0:b7d9a60d3d44 10 Timer timer;
muigaijosphat 1:ecf216fbee90 11
muigaijosphat 1:ecf216fbee90 12 int time_lapse,x;
muigaijosphat 1:ecf216fbee90 13 FATFileSystem fs("sd");
muigaijosphat 1:ecf216fbee90 14 FILE*fptr ;
muigaijosphat 1:ecf216fbee90 15
muigaijosphat 1:ecf216fbee90 16 void motion_write() {
muigaijosphat 1:ecf216fbee90 17
muigaijosphat 1:ecf216fbee90 18 if(myinput==0){
muigaijosphat 1:ecf216fbee90 19 timer.start();
muigaijosphat 1:ecf216fbee90 20 time_lapse= timer.read_ms(); //time between an interrupt
muigaijosphat 0:b7d9a60d3d44 21 }
muigaijosphat 1:ecf216fbee90 22
muigaijosphat 1:ecf216fbee90 23 // FILE*fptr = fopen("/sd/myfile.txt", "w");
muigaijosphat 1:ecf216fbee90 24
muigaijosphat 1:ecf216fbee90 25
muigaijosphat 1:ecf216fbee90 26 // fclose(fptr);
muigaijosphat 1:ecf216fbee90 27
muigaijosphat 1:ecf216fbee90 28 // printf("tiggers time is= :%d\r\n",time_lapse);
muigaijosphat 1:ecf216fbee90 29 timer.reset();
muigaijosphat 1:ecf216fbee90 30
muigaijosphat 1:ecf216fbee90 31 //return time_lapse;
muigaijosphat 1:ecf216fbee90 32
muigaijosphat 1:ecf216fbee90 33 }
muigaijosphat 1:ecf216fbee90 34 int main(){
muigaijosphat 1:ecf216fbee90 35 char date[64]; //string for storing the current date
muigaijosphat 1:ecf216fbee90 36 char timeofday[64]; //string for storing the current time
muigaijosphat 1:ecf216fbee90 37
muigaijosphat 1:ecf216fbee90 38 time_t seconds; //time_t variable to read the number of seconds since January 1, 1970 for time calculations
muigaijosphat 1:ecf216fbee90 39 //time_t now;
muigaijosphat 1:ecf216fbee90 40
muigaijosphat 1:ecf216fbee90 41 struct tm t; //time structure for setting the time
muigaijosphat 1:ecf216fbee90 42 time_t mytime = time(NULL);
muigaijosphat 1:ecf216fbee90 43 char * time_str = ctime(&mytime);
muigaijosphat 1:ecf216fbee90 44 time_str[strlen(time_str)-1] = '\0';
muigaijosphat 1:ecf216fbee90 45 printf("Current Time : %s\n", time_str);
muigaijosphat 1:ecf216fbee90 46 //set time structure to 20 Sep 2016 00:31:01
muigaijosphat 1:ecf216fbee90 47 time_t rawtime;
muigaijosphat 1:ecf216fbee90 48 struct tm * timeinfo;
muigaijosphat 1:ecf216fbee90 49
muigaijosphat 1:ecf216fbee90 50 time ( &rawtime );
muigaijosphat 1:ecf216fbee90 51 timeinfo = localtime ( &rawtime );
muigaijosphat 1:ecf216fbee90 52 /* printf ( "Current local time and date: %s", asctime (timeinfo) );
muigaijosphat 1:ecf216fbee90 53 t.tm_year = 2019 - 1900;
muigaijosphat 1:ecf216fbee90 54 t.tm_mon = 6 - 1;
muigaijosphat 1:ecf216fbee90 55 t.tm_mday = 11;
muigaijosphat 1:ecf216fbee90 56 t.tm_hour = 15;
muigaijosphat 1:ecf216fbee90 57 t.tm_min = 26;
muigaijosphat 1:ecf216fbee90 58 t.tm_sec = 00;
muigaijosphat 1:ecf216fbee90 59 set_time(mktime(&t));*/
muigaijosphat 1:ecf216fbee90 60 int err = fs.mount(&sd);
muigaijosphat 1:ecf216fbee90 61 printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
muigaijosphat 1:ecf216fbee90 62 if (err)
muigaijosphat 1:ecf216fbee90 63 return err;
muigaijosphat 1:ecf216fbee90 64 time_lapse= timer.read_ms();
muigaijosphat 1:ecf216fbee90 65 // FILE*fptr = fopen("/sd/myfiles.txt", "a");v
muigaijosphat 1:ecf216fbee90 66 motion_sensor.fall( &motion_write);
muigaijosphat 1:ecf216fbee90 67 while(1){
muigaijosphat 1:ecf216fbee90 68 if(myinput==1){wait(3);
muigaijosphat 1:ecf216fbee90 69 FILE*fptr = fopen("/sd/dspclass.txt", "a");
muigaijosphat 1:ecf216fbee90 70
muigaijosphat 1:ecf216fbee90 71 if ( fptr == NULL ) {
muigaijosphat 1:ecf216fbee90 72 printf( "Could not open file test.c" ) ;
muigaijosphat 1:ecf216fbee90 73 return 1;
muigaijosphat 1:ecf216fbee90 74 }
muigaijosphat 1:ecf216fbee90 75
muigaijosphat 1:ecf216fbee90 76 printf("OUR FILE IS SUCCESSFUL CREATED\t");
muigaijosphat 1:ecf216fbee90 77
muigaijosphat 1:ecf216fbee90 78 seconds = time(NULL); //read the new time value
muigaijosphat 1:ecf216fbee90 79 strftime(date, 32, "%d/%m/%y", localtime(&seconds)); //create a date string from the time value
muigaijosphat 1:ecf216fbee90 80 strftime(timeofday, 32, "%H:%M:%S", localtime(&seconds)); //create a time string from the time value
muigaijosphat 1:ecf216fbee90 81
muigaijosphat 1:ecf216fbee90 82 fprintf(fptr, "%s timelapse is %d\r\n", asctime (timeinfo), time_lapse); //write the date string, time string, and analog integer value to the file
muigaijosphat 1:ecf216fbee90 83 printf( "%s %d\r\n", asctime (timeinfo),time_lapse); //the /r/n combination puts the entries on different lines in the file
muigaijosphat 1:ecf216fbee90 84 //close the file to prevent corrupt f
muigaijosphat 1:ecf216fbee90 85 // fprintf(fptr,"%d\r\n",time_lapse);
muigaijosphat 1:ecf216fbee90 86
muigaijosphat 1:ecf216fbee90 87 // printf("tiggers time is= :%d\r\n",time_lapse);
muigaijosphat 1:ecf216fbee90 88
muigaijosphat 1:ecf216fbee90 89
muigaijosphat 1:ecf216fbee90 90 fclose(fptr);
muigaijosphat 1:ecf216fbee90 91 // wait(1);
muigaijosphat 1:ecf216fbee90 92 }
muigaijosphat 1:ecf216fbee90 93
muigaijosphat 1:ecf216fbee90 94 }
muigaijosphat 1:ecf216fbee90 95
muigaijosphat 1:ecf216fbee90 96
muigaijosphat 1:ecf216fbee90 97
muigaijosphat 1:ecf216fbee90 98 }
muigaijosphat 1:ecf216fbee90 99