GSOE Belueftung DS18B20
Dependencies: LCD_i2c_GSOE DS1820
Revision 1:fe12bf2ad337, committed 2015-03-26
- Comitter:
- hudakz
- Date:
- Thu Mar 26 20:58:32 2015 +0000
- Parent:
- 0:77a366f9ba45
- Child:
- 2:a680194ce6df
- Commit message:
- Sensor array sample added.
Changed in this revision
--- a/DS1820.lib Thu Mar 19 19:25:49 2015 +0000 +++ b/DS1820.lib Thu Mar 26 20:58:32 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/hudakz/code/DS1820/#a250babd0a9f +http://developer.mbed.org/users/hudakz/code/DS1820/#4403a206e78a
--- a/OneWire.lib Thu Mar 19 19:25:49 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/hudakz/code/OneWire/#acf75feb0947
--- a/main.cpp Thu Mar 19 19:25:49 2015 +0000 +++ b/main.cpp Thu Mar 26 20:58:32 2015 +0000 @@ -1,24 +1,56 @@ /* * Simple DS1820 sensor demo + * + * Note: Don't forget to connect a 4.7k Ohm resistor + * between the DS1820's data pin and the +3.3V pin + * */ #include "mbed.h" #include "DS1820.h" Serial serial(USBTX, USBRX); - + int main() { - DS1820 ds1820(PA_9); - - // detect and initialize DS1820 sensor + DS1820 ds1820(PA_9); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin + if(ds1820.begin()) { - ds1820.startConversion(); // start temperature conversion - wait(1.0); // wait to complete temperature conversion + ds1820.startConversion(); + wait(1.0); while(1) { - serial.printf("temp = %3.1f\r\n", ds1820.read()); // read temperature - ds1820.startConversion(); // start temperature conversion - wait(1.0); // wait to complete temperature conversion + serial.printf("temp = %3.1f\r\n", ds1820.read()); // read temperature + ds1820.startConversion(); // start temperature conversion + wait(1.0); // let DS1820 complete the temperature conversion } } else serial.printf("No DS1820 sensor found!\r\n"); } + + +// You can create an array of sensors: + +//int main() { +// DS1820 ds1820[3] = {DS1820(PA_8), DS1820(PA_9), DS1820(PC_7)}; +// +// for(int i = 0; i < 3; i++) { +// if(!ds1820[i].begin()) { +// serial.printf("Couldn't find sensor %d", i); +// } else +// ds1820[i].startConversion(); +// } +// +// wait(1.0); // let DS1820s complete the temperature conversion +// +// while(1) { +// for(int i = 0; i < 3; i++) { +// serial.printf("temp%d = %3.1f\r\n", i, ds1820[i].read()); // read temperature +// ds1820[i].startConversion(); // start temperature conversion +// } +// wait(1.0); // let DS1820s complete the temperature conversion +// } +//} + + + + + \ No newline at end of file