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.
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE DS1820
main.cpp
00001 //basiert auf dem DS1820-Example von Paul Staron 00002 00003 #include "mbed.h" 00004 #include "DS1820.h" 00005 #include "LCD.h" 00006 00007 DigitalOut led(LED1); 00008 lcd mylcd; 00009 00010 #define DATA_PIN PB_0 //Anschluss S 00011 //GND Anschluss - 00012 //3,3V mittlerer Anschluss 00013 00014 #define MAX_PROBES 16 00015 DS1820* probe[MAX_PROBES]; 00016 00017 Timer t; 00018 00019 int DS; 00020 float Temp[16]; 00021 00022 int main(){ 00023 mylcd.clear(); 00024 printf("\033[0m\033[2J\033[HInitialise...!\n\n"); 00025 00026 while (DS1820::unassignedProbe(DATA_PIN)) { 00027 probe[DS] = new DS1820(DATA_PIN); 00028 DS++; 00029 if (DS == MAX_PROBES) { 00030 break; 00031 } 00032 } 00033 00034 if (!DS) { 00035 printf("No Sensors found!\n\n"); 00036 ThisThread::sleep_for(chrono::milliseconds(1000)); 00037 NVIC_SystemReset(); 00038 } 00039 00040 // set each probe resolution, default is 12bit (750ms) 00041 probe[0]->setResolution(9); 00042 // probe[0]->setResolution(10); 00043 // probe[0]->setResolution(11); 00044 // probe[0]->setResolution(12); 00045 // probe[1]->setResolution(9); 00046 // probe[2]->setResolution(10); 00047 00048 t.start(); 00049 00050 while(1) { 00051 00052 printf("\033[0m\033[2J\033[HDS Sensor data..\n\n"); 00053 00054 int DS_error = 0; 00055 for (int i = 0; i < DS; i++) { 00056 Temp[i] = probe[i]->temperature(); 00057 if(Temp[i]==-1000) { 00058 Temp[i] = probe[i]->temperature(); // get read temp again if error 00059 DS_error++; 00060 } 00061 00062 mylcd.cursorpos(0x40); 00063 mylcd.printf("%3.1f ",Temp[i]); 00064 } 00065 printf("\nDS errors: %d\n\n", DS_error); 00066 00067 printf("Start conversion\n"); 00068 t.reset(); 00069 // don't wait for conversion, but do something that takes at least 750ms before reading the sensors 00070 //if(DS>0){probe[0]->convertTemperature(0, DS1820::all_devices);} 00071 00072 // wait for conversion, can take up to 750ms(12 bit mode) 00073 if(DS>0){probe[0]->convertTemperature(1, DS1820::all_devices);} 00074 00075 printf("\nConvert process time: %0.6f Seconds\n", chrono::duration<float>(t.elapsed_time()).count()); 00076 00077 ThisThread::sleep_for(chrono::milliseconds(1000)); 00078 } 00079 }
Generated on Thu Jul 21 2022 15:59:31 by
1.7.2