Tuan PM / Mbed 2 deprecated ds18b20_test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DS1820.h"
00003 
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 
00006 const int MAX_PROBES = 3;
00007 DS1820 probe[3] = {D2, D2, D2};
00008 
00009 
00010 int main()
00011 {
00012     int i;
00013     int devices_found=0;
00014     
00015     //pc.attach(&pcRx, pc.RxIrq);
00016     pc.printf("Started\r\n");
00017 
00018     pc.printf("search_ROM_setup\r\n");
00019     probe[0].search_ROM_setup();
00020     pc.printf("search_ROM\r\n");
00021     while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
00022           devices_found++;
00023     
00024     // If maximum number of probes are found,
00025     // bump the counter to include the last array entry
00026     if (probe[devices_found].ROM[0] != 0xFF)
00027         devices_found++;
00028     pc.printf("devices found:%d\r\n", devices_found);
00029 
00030 
00031     while(1) {
00032         probe[0].convert_temperature(DS1820::all_devices);
00033         for (i=0; i<devices_found; i++) {
00034             pc.printf("Device[%d]: %3.1f \r\n",i, probe[i].temperature('c'));
00035         }
00036         wait(1.0); // 1 sec
00037     }
00038 }