sensore digitale di temperatura

Dependencies:   mbed

Committer:
mariangelamone
Date:
Sat Jan 29 16:53:42 2022 +0000
Revision:
3:3f6e2ad53c91
Parent:
2:b369cd116bf1
DS18B20

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariangelamone 3:3f6e2ad53c91 1
TuanPM 0:6cb99f312e0e 2 #include "mbed.h"
TuanPM 0:6cb99f312e0e 3 #include "DS1820.h"
TuanPM 0:6cb99f312e0e 4 Serial pc(SERIAL_TX, SERIAL_RX);
jchari 2:b369cd116bf1 5 const int MAX_PROBES = 1;
jchari 2:b369cd116bf1 6 DS1820 probe[1] = {A0};
TuanPM 0:6cb99f312e0e 7 int main()
TuanPM 0:6cb99f312e0e 8 {
TuanPM 1:10bbb8a13329 9 int i;
TuanPM 0:6cb99f312e0e 10 int devices_found=0;
TuanPM 0:6cb99f312e0e 11
TuanPM 0:6cb99f312e0e 12 //pc.attach(&pcRx, pc.RxIrq);
TuanPM 0:6cb99f312e0e 13 pc.printf("Started\r\n");
TuanPM 0:6cb99f312e0e 14
TuanPM 0:6cb99f312e0e 15 pc.printf("search_ROM_setup\r\n");
TuanPM 0:6cb99f312e0e 16 probe[0].search_ROM_setup();
TuanPM 0:6cb99f312e0e 17 pc.printf("search_ROM\r\n");
TuanPM 0:6cb99f312e0e 18 while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
TuanPM 0:6cb99f312e0e 19 devices_found++;
TuanPM 0:6cb99f312e0e 20
TuanPM 0:6cb99f312e0e 21 // If maximum number of probes are found,
TuanPM 0:6cb99f312e0e 22 // bump the counter to include the last array entry
TuanPM 0:6cb99f312e0e 23 if (probe[devices_found].ROM[0] != 0xFF)
TuanPM 0:6cb99f312e0e 24 devices_found++;
TuanPM 0:6cb99f312e0e 25 pc.printf("devices found:%d\r\n", devices_found);
TuanPM 0:6cb99f312e0e 26
TuanPM 0:6cb99f312e0e 27
TuanPM 0:6cb99f312e0e 28 while(1) {
TuanPM 0:6cb99f312e0e 29 probe[0].convert_temperature(DS1820::all_devices);
TuanPM 0:6cb99f312e0e 30 for (i=0; i<devices_found; i++) {
mariangelamone 3:3f6e2ad53c91 31 // pc.printf("Device[%d]: %3.1f \r\n",i, probe[i].temperature('f'));
mariangelamone 3:3f6e2ad53c91 32 float t=probe[i].temperature('f');
mariangelamone 3:3f6e2ad53c91 33 float tc=(t-32)/1.8; //da Farenheit a Celsius
mariangelamone 3:3f6e2ad53c91 34 pc.printf("Device[%d]: %3.1f \r\n",i, t);
mariangelamone 3:3f6e2ad53c91 35 pc.printf("Device[%d]: %3.1f \r\n",i, tc);
TuanPM 0:6cb99f312e0e 36 }
jchari 2:b369cd116bf1 37 wait(1); // 1 sec
TuanPM 0:6cb99f312e0e 38 }
TuanPM 0:6cb99f312e0e 39 }