testing DS1820
Fork of DS1820_HelloWorld by
main.cpp@5:7cc3a5fc200d, 2017-08-01 (annotated)
- Committer:
- zappo
- Date:
- Tue Aug 01 10:47:48 2017 +0000
- Revision:
- 5:7cc3a5fc200d
- Parent:
- 3:f483abe4bc57
test1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:e069f9f26768 | 1 | #define MULTIPLE_PROBES |
zappo | 5:7cc3a5fc200d | 2 | #define DATA_PIN A0 // A0 = P0_23 |
Sissors | 0:e069f9f26768 | 3 | |
Sissors | 0:e069f9f26768 | 4 | |
Sissors | 0:e069f9f26768 | 5 | #ifdef MULTIPLE_PROBES |
Sissors | 0:e069f9f26768 | 6 | |
Sissors | 0:e069f9f26768 | 7 | #include "mbed.h" |
Sissors | 0:e069f9f26768 | 8 | #include "DS1820.h" |
Sissors | 0:e069f9f26768 | 9 | |
Sissors | 0:e069f9f26768 | 10 | #define MAX_PROBES 16 |
Sissors | 0:e069f9f26768 | 11 | |
Sissors | 0:e069f9f26768 | 12 | DS1820* probe[MAX_PROBES]; |
zappo | 5:7cc3a5fc200d | 13 | Serial pc(USBTX, USBRX); |
Sissors | 0:e069f9f26768 | 14 | |
zappo | 5:7cc3a5fc200d | 15 | int main() |
zappo | 5:7cc3a5fc200d | 16 | { |
zappo | 5:7cc3a5fc200d | 17 | pc.baud(115200); |
zappo | 5:7cc3a5fc200d | 18 | pc.printf("Initialize probes..."); |
zappo | 5:7cc3a5fc200d | 19 | |
Sissors | 0:e069f9f26768 | 20 | // Initialize the probe array to DS1820 objects |
Sissors | 0:e069f9f26768 | 21 | int num_devices = 0; |
Sissors | 0:e069f9f26768 | 22 | while(DS1820::unassignedProbe(DATA_PIN)) { |
Sissors | 0:e069f9f26768 | 23 | probe[num_devices] = new DS1820(DATA_PIN); |
Sissors | 0:e069f9f26768 | 24 | num_devices++; |
Sissors | 0:e069f9f26768 | 25 | if (num_devices == MAX_PROBES) |
Sissors | 0:e069f9f26768 | 26 | break; |
Sissors | 0:e069f9f26768 | 27 | } |
Sissors | 0:e069f9f26768 | 28 | |
Sissors | 0:e069f9f26768 | 29 | printf("Found %d device(s)\r\n\n", num_devices); |
Sissors | 0:e069f9f26768 | 30 | while(1) { |
Sissors | 0:e069f9f26768 | 31 | probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
Sissors | 0:e069f9f26768 | 32 | for (int i = 0; i<num_devices; i++) |
zappo | 5:7cc3a5fc200d | 33 | printf("Device %d returns %3.1f oC", i, probe[i]->temperature()); |
Sissors | 0:e069f9f26768 | 34 | printf("\r\n"); |
zappo | 5:7cc3a5fc200d | 35 | wait_us(10000); |
Sissors | 0:e069f9f26768 | 36 | } |
Sissors | 0:e069f9f26768 | 37 | |
Sissors | 0:e069f9f26768 | 38 | } |
Sissors | 0:e069f9f26768 | 39 | |
Sissors | 0:e069f9f26768 | 40 | #else |
Sissors | 0:e069f9f26768 | 41 | #include "mbed.h" |
Sissors | 0:e069f9f26768 | 42 | #include "DS1820.h" |
Sissors | 0:e069f9f26768 | 43 | |
Sissors | 0:e069f9f26768 | 44 | DS1820 probe(DATA_PIN); |
zappo | 5:7cc3a5fc200d | 45 | Serial pc(USBTX, USBRX); |
Sissors | 0:e069f9f26768 | 46 | |
zappo | 5:7cc3a5fc200d | 47 | int main() |
zappo | 5:7cc3a5fc200d | 48 | { |
zappo | 5:7cc3a5fc200d | 49 | pc.baud(115200); |
zappo | 5:7cc3a5fc200d | 50 | pc.printf("Initialize probes..."); |
zappo | 5:7cc3a5fc200d | 51 | |
zappo | 5:7cc3a5fc200d | 52 | while(1) |
zappo | 5:7cc3a5fc200d | 53 | { |
Sissors | 0:e069f9f26768 | 54 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
zappo | 5:7cc3a5fc200d | 55 | pc.printf("It is %3.1foC\r\n", probe.temperature()); |
Sissors | 0:e069f9f26768 | 56 | wait(1); |
Sissors | 0:e069f9f26768 | 57 | } |
Sissors | 0:e069f9f26768 | 58 | } |
Sissors | 0:e069f9f26768 | 59 | |
Sissors | 0:e069f9f26768 | 60 | #endif |