Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "DS1820.h" 00003 00004 Serial pc(USBTX, USBRX); 00005 DigitalOut led(LED1); 00006 DS1820 ds1820(D8); // substitute D8 with actual mbed pin name connected to 1-wire bus 00007 float temp = 0; 00008 int result = 0; 00009 00010 int main() 00011 { 00012 pc.printf("\r\n--Starting--\r\n"); 00013 if (ds1820.begin()) { 00014 while (1) { 00015 ds1820.startConversion(); // start temperature conversion from analog to digital 00016 wait(1.0); // let DS1820 complete the temperature conversion 00017 result = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) 00018 switch (result) { 00019 case 0: // no errors -> 'temp' contains the value of measured temperature 00020 pc.printf("temp = %3.1f%cC\r\n", temp, 176); 00021 break; 00022 00023 case 1: // no sensor present -> 'temp' is not updated 00024 pc.printf("no sensor present\n\r"); 00025 break; 00026 00027 case 2: // CRC error -> 'temp' is not updated 00028 pc.printf("CRC error\r\n"); 00029 } 00030 00031 led = !led; 00032 } 00033 } 00034 else 00035 pc.printf("No DS1820 sensor found!\r\n"); 00036 }
Generated on Sun Jul 17 2022 11:19:39 by
1.7.2