ds18b20 for senior design
Dependencies: mbed
Fork of ds18b20_test by
Diff: main.cpp
- Revision:
- 0:6cb99f312e0e
- Child:
- 1:10bbb8a13329
diff -r 000000000000 -r 6cb99f312e0e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 27 17:22:57 2014 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +#include "DS1820.h" + +Serial pc(SERIAL_TX, SERIAL_RX); + +const int MAX_PROBES = 3; +DS1820 probe[3] = {D2, D2, D2}; + + +int main() +{ + int j = 1, i; + int devices_found=0; + + //pc.attach(&pcRx, pc.RxIrq); + pc.printf("Started\r\n"); + + pc.printf("search_ROM_setup\r\n"); + probe[0].search_ROM_setup(); + pc.printf("search_ROM\r\n"); + while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1) + devices_found++; + + // If maximum number of probes are found, + // bump the counter to include the last array entry + if (probe[devices_found].ROM[0] != 0xFF) + devices_found++; + pc.printf("devices found:%d\r\n", devices_found); + + + while(1) { + pc.printf("This program runs since %d seconds.\r\n", j++); + probe[0].convert_temperature(DS1820::all_devices); + for (i=0; i<devices_found; i++) { + pc.printf("Device[%d]: %3.1f \r\n",i, probe[i].temperature('c')); + } + wait(1.0); // 1 sec + } +}