![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Threads
Dependencies: mbed C12832 LM75B
main.cpp@6:e883d7b9c790, 2020-11-10 (annotated)
- Committer:
- ciaranom
- Date:
- Tue Nov 10 12:11:20 2020 +0000
- Revision:
- 6:e883d7b9c790
- Parent:
- 5:608f2bf4d3f7
- Child:
- 7:d20cc6a9060c
Cyber Physical Systems Lab 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:ce7a8546502b | 1 | #include "mbed.h" |
chris | 2:9e757151de9b | 2 | #include "LM75B.h" |
chris | 5:608f2bf4d3f7 | 3 | #include "C12832.h" |
okano | 0:ce7a8546502b | 4 | |
chris | 5:608f2bf4d3f7 | 5 | C12832 lcd(p5, p7, p6, p8, p11); |
chris | 5:608f2bf4d3f7 | 6 | |
chris | 4:6df97cb10041 | 7 | LM75B sensor(p28,p27); |
chris | 4:6df97cb10041 | 8 | Serial pc(USBTX,USBRX); |
okano | 0:ce7a8546502b | 9 | |
ciaranom | 6:e883d7b9c790 | 10 | |
ciaranom | 6:e883d7b9c790 | 11 | |
chris | 2:9e757151de9b | 12 | int main () |
okano | 0:ce7a8546502b | 13 | { |
ciaranom | 6:e883d7b9c790 | 14 | //variables |
ciaranom | 6:e883d7b9c790 | 15 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
ciaranom | 6:e883d7b9c790 | 16 | FILE *fp = fopen("/local/temp2.csv", "w"); // Open "out.txt" on the local file system for writing |
ciaranom | 6:e883d7b9c790 | 17 | int i =0; |
ciaranom | 6:e883d7b9c790 | 18 | //float temps [5]; |
ciaranom | 6:e883d7b9c790 | 19 | //float sensorval; |
chris | 4:6df97cb10041 | 20 | //Try to open the LM75B |
ciaranom | 6:e883d7b9c790 | 21 | if (sensor.open()) |
ciaranom | 6:e883d7b9c790 | 22 | { |
chris | 4:6df97cb10041 | 23 | printf("Device detected!\n"); |
ciaranom | 6:e883d7b9c790 | 24 | while (i < 5) |
ciaranom | 6:e883d7b9c790 | 25 | { |
chris | 4:6df97cb10041 | 26 | lcd.cls(); |
chris | 4:6df97cb10041 | 27 | lcd.locate(0,3); |
ciaranom | 6:e883d7b9c790 | 28 | lcd.printf("Temp = %.3f", (float)sensor); |
ciaranom | 6:e883d7b9c790 | 29 | wait(0.5); |
ciaranom | 6:e883d7b9c790 | 30 | fprintf(fp, "%.3f,", (float)sensor); |
ciaranom | 6:e883d7b9c790 | 31 | //cur_temp = (float)sensor; |
ciaranom | 6:e883d7b9c790 | 32 | //sensorval = (float)sensor; |
ciaranom | 6:e883d7b9c790 | 33 | //printf("\n\r %.3f\n\r",sensorval); |
ciaranom | 6:e883d7b9c790 | 34 | //temps[i] = sensorval; |
ciaranom | 6:e883d7b9c790 | 35 | //pc. printf("%.3f ",temps[i]); |
ciaranom | 6:e883d7b9c790 | 36 | i = i+1; |
ciaranom | 6:e883d7b9c790 | 37 | wait(0.5); |
ciaranom | 6:e883d7b9c790 | 38 | }//end while loop |
ciaranom | 6:e883d7b9c790 | 39 | } |
ciaranom | 6:e883d7b9c790 | 40 | else |
ciaranom | 6:e883d7b9c790 | 41 | { |
ciaranom | 6:e883d7b9c790 | 42 | error("Device not detected!\n"); |
ciaranom | 6:e883d7b9c790 | 43 | }//end if sensor open |
ciaranom | 6:e883d7b9c790 | 44 | |
ciaranom | 6:e883d7b9c790 | 45 | //for(int j = 0; j<i; j++) //causing infinite loop |
ciaranom | 6:e883d7b9c790 | 46 | |
ciaranom | 6:e883d7b9c790 | 47 | |
ciaranom | 6:e883d7b9c790 | 48 | //close files |
ciaranom | 6:e883d7b9c790 | 49 | fclose(fp); |
ciaranom | 6:e883d7b9c790 | 50 | |
ciaranom | 6:e883d7b9c790 | 51 | FILE * pFile; |
ciaranom | 6:e883d7b9c790 | 52 | char mystring [5]; |
chris | 4:6df97cb10041 | 53 | |
ciaranom | 6:e883d7b9c790 | 54 | pFile = fopen ("/local/temp2.csv" , "r"); |
ciaranom | 6:e883d7b9c790 | 55 | if (pFile == NULL) perror ("Error opening file"); |
ciaranom | 6:e883d7b9c790 | 56 | else { |
ciaranom | 6:e883d7b9c790 | 57 | if ( fgets (mystring , 5 , pFile) != NULL ) |
ciaranom | 6:e883d7b9c790 | 58 | pc.printf(mystring); |
ciaranom | 6:e883d7b9c790 | 59 | fclose (pFile); |
ciaranom | 6:e883d7b9c790 | 60 | //pc.printf("%.3f ",temps[i]); |
ciaranom | 6:e883d7b9c790 | 61 | } |
ciaranom | 6:e883d7b9c790 | 62 | return 0; |
ciaranom | 6:e883d7b9c790 | 63 | |
ciaranom | 6:e883d7b9c790 | 64 | //printf("%.3f",temps[i]); |
chris | 2:9e757151de9b | 65 | } |
ciaranom | 6:e883d7b9c790 | 66 | //end main |
okano | 0:ce7a8546502b | 67 | |
ciaranom | 6:e883d7b9c790 | 68 |