DS1820 Hello World

Dependencies:   mbed DS1820_HelloWorld DS1820

Committer:
Sissors
Date:
Mon Feb 24 21:24:38 2014 +0000
Revision:
0:e069f9f26768
Child:
2:d644c874ea0c
DS1820 HelloWorld

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:e069f9f26768 1 #define MULTIPLE_PROBES
Sissors 0:e069f9f26768 2 #define DATA_PIN D13
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];
Sissors 0:e069f9f26768 13
Sissors 0:e069f9f26768 14 int main() {
Sissors 0:e069f9f26768 15 // Initialize the probe array to DS1820 objects
Sissors 0:e069f9f26768 16 int num_devices = 0;
Sissors 0:e069f9f26768 17 while(DS1820::unassignedProbe(DATA_PIN)) {
Sissors 0:e069f9f26768 18 probe[num_devices] = new DS1820(DATA_PIN);
Sissors 0:e069f9f26768 19 num_devices++;
Sissors 0:e069f9f26768 20 if (num_devices == MAX_PROBES)
Sissors 0:e069f9f26768 21 break;
Sissors 0:e069f9f26768 22 }
Sissors 0:e069f9f26768 23
Sissors 0:e069f9f26768 24 printf("Found %d device(s)\r\n\n", num_devices);
Sissors 0:e069f9f26768 25
Sissors 0:e069f9f26768 26 while(1) {
Sissors 0:e069f9f26768 27 probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
Sissors 0:e069f9f26768 28 for (int i = 0; i<num_devices; i++)
Sissors 0:e069f9f26768 29 printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature());
Sissors 0:e069f9f26768 30 printf("\r\n");
Sissors 0:e069f9f26768 31 wait(1);
Sissors 0:e069f9f26768 32 }
Sissors 0:e069f9f26768 33
Sissors 0:e069f9f26768 34 }
Sissors 0:e069f9f26768 35
Sissors 0:e069f9f26768 36 #else
Sissors 0:e069f9f26768 37 #include "mbed.h"
Sissors 0:e069f9f26768 38 #include "DS1820.h"
Sissors 0:e069f9f26768 39
Sissors 0:e069f9f26768 40 DS1820 probe(DATA_PIN);
Sissors 0:e069f9f26768 41
Sissors 0:e069f9f26768 42 int main() {
Sissors 0:e069f9f26768 43 while(1) {
Sissors 0:e069f9f26768 44 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
Sissors 0:e069f9f26768 45 printf("It is %3.1foC\r\n", probe.temperature());
Sissors 0:e069f9f26768 46 wait(1);
Sissors 0:e069f9f26768 47 }
Sissors 0:e069f9f26768 48 }
Sissors 0:e069f9f26768 49
Sissors 0:e069f9f26768 50 #endif