Jake Billingham
/
mbed_settingsproto
sdvsv
main.cpp@0:e040d34c2969, 2017-10-22 (annotated)
- Committer:
- jbillingham
- Date:
- Sun Oct 22 18:16:23 2017 +0000
- Revision:
- 0:e040d34c2969
dsfcsdv
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbillingham | 0:e040d34c2969 | 1 | //Import libraries |
jbillingham | 0:e040d34c2969 | 2 | #include "mbed.h" |
jbillingham | 0:e040d34c2969 | 3 | #include "stdio.h" |
jbillingham | 0:e040d34c2969 | 4 | #include "math.h" |
jbillingham | 0:e040d34c2969 | 5 | |
jbillingham | 0:e040d34c2969 | 6 | //Establish serial connection |
jbillingham | 0:e040d34c2969 | 7 | Serial pc(USBTX, USBRX); |
jbillingham | 0:e040d34c2969 | 8 | //Create the local filesystem |
jbillingham | 0:e040d34c2969 | 9 | LocalFileSystem local("local"); |
jbillingham | 0:e040d34c2969 | 10 | |
jbillingham | 0:e040d34c2969 | 11 | //Define variables |
jbillingham | 0:e040d34c2969 | 12 | int N = 50; //Number of samples |
jbillingham | 0:e040d34c2969 | 13 | float T = 0.1; //Sample period |
jbillingham | 0:e040d34c2969 | 14 | |
jbillingham | 0:e040d34c2969 | 15 | int main() |
jbillingham | 0:e040d34c2969 | 16 | { |
jbillingham | 0:e040d34c2969 | 17 | FILE *settings; //Create file with pointer |
jbillingham | 0:e040d34c2969 | 18 | |
jbillingham | 0:e040d34c2969 | 19 | settings = fopen("/local/settings.txt", "w");//Open file for writing |
jbillingham | 0:e040d34c2969 | 20 | pc.printf("File open.\n"); //Indicates file open |
jbillingham | 0:e040d34c2969 | 21 | fprintf(settings, "%i %f", N, T); //Writes settings values onto file |
jbillingham | 0:e040d34c2969 | 22 | fclose(settings); //Close file |
jbillingham | 0:e040d34c2969 | 23 | pc.printf("Settings saved.\n"); |
jbillingham | 0:e040d34c2969 | 24 | |
jbillingham | 0:e040d34c2969 | 25 | //Define variables for output |
jbillingham | 0:e040d34c2969 | 26 | int value1; |
jbillingham | 0:e040d34c2969 | 27 | float value2; |
jbillingham | 0:e040d34c2969 | 28 | |
jbillingham | 0:e040d34c2969 | 29 | settings = fopen("/local/settings.txt" , "r"); //Open file for reading |
jbillingham | 0:e040d34c2969 | 30 | fseek(settings, 0 ,SEEK_SET); //Sets cursor to start of file |
jbillingham | 0:e040d34c2969 | 31 | fscanf(settings, "%i", &value1); //Scans for first number |
jbillingham | 0:e040d34c2969 | 32 | pc.printf("Settings are:\n"); |
jbillingham | 0:e040d34c2969 | 33 | pc.printf("%i\n", value1); //Outputs first number |
jbillingham | 0:e040d34c2969 | 34 | fseek(settings, sizeof(int), SEEK_SET); //Sets cursor to after first number |
jbillingham | 0:e040d34c2969 | 35 | fscanf(settings, "%f", &value2); //Scans for second number |
jbillingham | 0:e040d34c2969 | 36 | pc.printf("%f\n", value2); //Outputs second number |
jbillingham | 0:e040d34c2969 | 37 | fclose(settings); //Close file |
jbillingham | 0:e040d34c2969 | 38 | } |