Erik -
/
DS1820_HelloWorld
DS1820 Hello World
Revision 0:e069f9f26768, committed 2014-02-24
- Comitter:
- Sissors
- Date:
- Mon Feb 24 21:24:38 2014 +0000
- Child:
- 1:9100c4c37ad5
- Commit message:
- DS1820 HelloWorld
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DS1820.lib Mon Feb 24 21:24:38 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/DS1820/#2cd4928e8147
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 24 21:24:38 2014 +0000 @@ -0,0 +1,50 @@ +#define MULTIPLE_PROBES +#define DATA_PIN D13 + + +#ifdef MULTIPLE_PROBES + +#include "mbed.h" +#include "DS1820.h" + +#define MAX_PROBES 16 + +DS1820* probe[MAX_PROBES]; + +int main() { + // Initialize the probe array to DS1820 objects + int num_devices = 0; + while(DS1820::unassignedProbe(DATA_PIN)) { + probe[num_devices] = new DS1820(DATA_PIN); + num_devices++; + if (num_devices == MAX_PROBES) + break; + } + + printf("Found %d device(s)\r\n\n", num_devices); + + while(1) { + probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready + for (int i = 0; i<num_devices; i++) + printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature()); + printf("\r\n"); + wait(1); + } + +} + +#else +#include "mbed.h" +#include "DS1820.h" + +DS1820 probe(DATA_PIN); + +int main() { + while(1) { + probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready + printf("It is %3.1foC\r\n", probe.temperature()); + wait(1); + } +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Feb 24 21:24:38 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file