GSOE Belueftung DS18B20
Dependencies: LCD_i2c_GSOE DS1820
Revision 7:8beaacebc82d, committed 2019-01-27
- Comitter:
- hudakz
- Date:
- Sun Jan 27 14:12:49 2019 +0000
- Parent:
- 6:d68db387a734
- Child:
- 8:6373abe686d2
- Commit message:
- Updated.
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 |
--- a/DS1820.lib Sat Jan 26 21:22:44 2019 +0000 +++ b/DS1820.lib Sun Jan 27 14:12:49 2019 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/hudakz/code/DS1820/#9ff584b9809f +http://developer.mbed.org/users/hudakz/code/DS1820/#2439846f608e
--- a/main.cpp Sat Jan 26 21:22:44 2019 +0000 +++ b/main.cpp Sun Jan 27 14:12:49 2019 +0000 @@ -5,41 +5,43 @@ * between the DS1820's data pin and the +3.3V pin * */ - #include "mbed.h" #include "DS1820.h" Serial pc(USBTX, USBRX); DigitalOut led(LED1); -DS1820 ds1820(PB_11); // substitute p8 with actual mbed pin name connected to the DS1820 data pin +DS1820 ds1820(p8); // substitute p8 with actual mbed pin name connected to the DS1820 data pin float temp = 0; -int result = 0; - -int main() { - - if(ds1820.begin()) { - while(1) { - ds1820.startConversion(); // start temperature conversion from analog to digital - wait(1.0); // let DS1820 complete the temperature conversion +int result = 0; + +int main() +{ + if (ds1820.begin()) { + while (1) { + ds1820.startConversion(); // start temperature conversion from analog to digital + wait(1.0); // let DS1820 complete the temperature conversion result = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - switch(result) { - case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("temp = %3.1f%cC\r\n", temp, 176); - break; - case 1: // no sensor present -> 'temp' is not updated - pc.printf("no sensor present\n\r"); - break; - case 2: // CRC error -> 'temp' is not updated - pc.printf("CRC error\r\n"); - } + switch (result) { + case 0: // no errors -> 'temp' contains the value of measured temperature + pc.printf("temp = %3.1f%cC\r\n", temp, 176); + break; + + case 1: // no sensor present -> 'temp' is not updated + pc.printf("no sensor present\n\r"); + break; + + case 2: // CRC error -> 'temp' is not updated + pc.printf("CRC error\r\n"); + } + led = !led; } - } else + } + else pc.printf("No DS1820 sensor found!\r\n"); } // Array of sensors: - //int main() { // DS1820 ds1820[3] = {DS1820(PA_8), DS1820(PA_9), DS1820(PC_7)}; // @@ -48,8 +50,8 @@ // serial.printf("Cannot find sensor %d", i); // } else // ds1820[i].startConversion(); -// } -// wait(1.0); // let DS1820s complete the temperature conversion +// } +// wait(1.0); // let DS1820s complete the temperature conversion // while(1) { // for(int i = 0; i < 3; i++) { // if(ds1820[i].isPresent() { @@ -59,10 +61,5 @@ // } // wait(1.0); // let DS1820s complete the temperature conversion // } -//} -// - - - - - +//} +//