Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL SDFileSystemSeth mbed
Fork of Opstellingbachelor_opdracht by
Diff: main.cpp
- Revision:
- 10:96c194005985
- Parent:
- 9:d9ba61ce7a29
- Child:
- 11:d3b519e36914
--- a/main.cpp Tue May 22 10:33:05 2018 +0000 +++ b/main.cpp Mon May 28 06:42:16 2018 +0000 @@ -43,16 +43,11 @@ volatile bool start = 0; volatile bool meas = 0; -float fcs_read; float read_TC; int trial_numb = 0; -int cal_numb = 1; -char filename_torque[64]; char filename_temp[64]; -char filename_cal[64]; - @@ -91,7 +86,7 @@ wait_us(0.1); //wait for 100ns SCK_1 = 1; //then set clock high again wait_us(0.1); //wait for 100ns - for (int j = 0; j < 3; j++) { //read out bits for each thermocouple (0 to 11) + for (int j = 0; j < 3; j++) { //read out bits for each thermocouple (0 to 11) if (pins[j]) { b[j] |= (1 << i); //bitshift } @@ -100,7 +95,7 @@ CS_1 = 1; - for (int j = 0; j < 3; j++) { //for every thermocouple (starting from 0 to 11, so 12 in total) + for (int j = 0; j < 3; j++) { //for every thermocouple (starting from 0 to 11, so 12 in total) if (b[j] & 0x1) { //b[j] contains the bits that are received from every chip. if least significant bit is 1, then open circuit. b[j] = 20000; } else { @@ -110,8 +105,8 @@ fprintf(fp, "%.3f \n\r", d); pc.printf("%.3f\t", d); } - // pc.printf("\n\r"); fprintf(fp, "\n\r"); + pc.printf("\n\r"); return; } @@ -119,11 +114,7 @@ void getsample(bool meas) { if(meas){ // alleen data uitlezen en opslaan als meas = 1 - fcs_read = fcs.read(); // capture torque sensor data - fprintf(fp, "%.3f\t", fcs_read); // output data to file - // pc.printf("%.3f\t", fcs_read); // output data to screen - read_TC = readTC(); // call function to read thermocouple data - fprintf(fp,"%.3f\t", read_TC); + read_TC = readTC(); // call function to read thermocouple data } return; } @@ -147,28 +138,6 @@ if(pc.readable()) { // if character available switch(pc.getc()) { // read a character from keyboard - case 'c': - led_control(led_on,led_on,led_off); //orange LED during calibration - sprintf(filename_cal, "/sd/cal_torque_%d.txt", cal_numb); //construct new textfile - sprintf(filename_cal, "/sd/cal_temp_%d.txt", cal_numb); - fp = fopen(filename_cal, "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } else { - while(1) { - for (int i = 0; i<50; i++) { //get 50 samples from torque sensor - fcs_read = fcs.read(); - fprintf(fp, "%.3f\t \n\r", fcs_read); //output values to the screen - } - break; - } - } - fclose(fp); //close file - - cal_numb++; //increment calibration number - pc.printf("File saved as %s\n\r", filename_cal); //print name of calibration file to screen - pc.printf("Press 'c' to record new calibration or 't' to start new trial\n\r"); // print message to screen - break; case 't': trial_numb++; pc.printf("Trial number: %d\n\r", trial_numb); @@ -178,9 +147,7 @@ start = !start; if (start) { led_control(led_off,led_on,led_off); //green LED during measurement - sprintf(filename_torque, "/sd/trial%d.txt", trial_numb); //construct new textfile to store data from torque sensor sprintf(filename_temp, "/sd/temp%d.txt", trial_numb); - fp = fopen(filename_torque, "w"); fp = fopen(filename_temp, "w"); if(fp == NULL) { @@ -192,12 +159,12 @@ } break; } else { - led_control(led_on,led_off,led_off); // RED LED when ready to stopped measuring + led_control(led_on,led_off,led_off); // RED LED when ready to stopped measuring meas = 0; // hiermee stop je de output naar het .txt file fclose(fp); - pc.printf("File saved as %s\n\r", filename_torque); // print filename to screen - pc.printf("Press 'c' to perform new calibration or 't' to start new trial\n\r"); // print message to screen + pc.printf("File saved as %s\n\r", filename_temp); // print filename to screen + pc.printf("Press 't' to start new trial\n\r"); // print message to screen } break;