Example program for the DS1820 library. It searches for connected devices, reports their addresses, and then displays their temperatures.
Fork of DS1820_HelloWorld by
Revision 5:a870fb672587, committed 2017-03-09
- Comitter:
- JLarkin
- Date:
- Thu Mar 09 04:04:16 2017 +0000
- Parent:
- 4:01060b5e01b4
- Commit message:
- Example DS1820 program reports device IDs and then reports temps
Changed in this revision
DS1820.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 01060b5e01b4 -r a870fb672587 DS1820.lib --- a/DS1820.lib Fri Jan 13 18:30:37 2017 +0000 +++ b/DS1820.lib Thu Mar 09 04:04:16 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Sissors/code/DS1820/#c591209285e9 +https://developer.mbed.org/teams/Whitworth-EN173-Resources/code/DS1820/#00ec4f27d7f5
diff -r 01060b5e01b4 -r a870fb672587 main.cpp --- a/main.cpp Fri Jan 13 18:30:37 2017 +0000 +++ b/main.cpp Thu Mar 09 04:04:16 2017 +0000 @@ -1,5 +1,5 @@ #define MULTIPLE_PROBES -#define DATA_PIN A0 +#define DATA_PIN p25 #ifdef MULTIPLE_PROBES @@ -21,11 +21,22 @@ break; } - printf("Found %d device(s)\r\n\n", num_devices); + printf("Found %d device(s)\r\n", num_devices); + unsigned long long fullName; + unsigned int firstName; + unsigned int lastName; + for (int i = 0; i<num_devices; i++) { + fullName = probe[i]->whoAmI(); + firstName = fullName >> 32; + lastName = fullName; + printf("\tID %d = %x%x\r\n", i, firstName, lastName); + } + printf("\n"); + 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("%3.1f C\t", i, probe[i]->temperature()); printf("\r\n"); wait(1); }