DS1820 Hello World

Dependencies:   DS1820 mbed

Committer:
Sissors
Date:
Fri Jan 13 18:30:37 2017 +0000
Revision:
4:01060b5e01b4
Parent:
3:f483abe4bc57
Updated everything to latest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:e069f9f26768 1 #define MULTIPLE_PROBES
Sissors 2:d644c874ea0c 2 #define DATA_PIN A0
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 while(1) {
Sissors 0:e069f9f26768 26 probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
Sissors 0:e069f9f26768 27 for (int i = 0; i<num_devices; i++)
Sissors 0:e069f9f26768 28 printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature());
Sissors 0:e069f9f26768 29 printf("\r\n");
Sissors 0:e069f9f26768 30 wait(1);
Sissors 0:e069f9f26768 31 }
Sissors 0:e069f9f26768 32
Sissors 0:e069f9f26768 33 }
Sissors 0:e069f9f26768 34
Sissors 0:e069f9f26768 35 #else
Sissors 0:e069f9f26768 36 #include "mbed.h"
Sissors 0:e069f9f26768 37 #include "DS1820.h"
Sissors 0:e069f9f26768 38
Sissors 0:e069f9f26768 39 DS1820 probe(DATA_PIN);
Sissors 0:e069f9f26768 40
Sissors 0:e069f9f26768 41 int main() {
Sissors 0:e069f9f26768 42 while(1) {
Sissors 0:e069f9f26768 43 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
Sissors 0:e069f9f26768 44 printf("It is %3.1foC\r\n", probe.temperature());
Sissors 0:e069f9f26768 45 wait(1);
Sissors 0:e069f9f26768 46 }
Sissors 0:e069f9f26768 47 }
Sissors 0:e069f9f26768 48
Sissors 0:e069f9f26768 49 #endif