本文整理汇总了C++中DallasTemperature类的典型用法代码示例。如果您正苦于以下问题:C++ DallasTemperature类的具体用法?C++ DallasTemperature怎么用?C++ DallasTemperature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DallasTemperature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: oneWire
double Sensor::getDS18B20Reading()
{
OneWire oneWire(index);
DallasTemperature sensor = DallasTemperature(&oneWire);
sensor.setResolution(12);
sensor.begin();
sensor.requestTemperatures();
return sensor.getTempCByIndex(0);
}
示例2: setTemperature
bool setTemperature(unsigned long iTemp){
//Serial.println("Req temp");
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println("Requested");
float tempr = sensors.getTempCByIndex(0);
//Serial.println("Temp res");
//displayData("Temp res");
char buffer[256];
displayData(itoa(tempr, buffer, 10));
displayData(",");
displayData(itoa(iTemp, buffer, 10));
displayData(",");
//Serial.println("params");
// Serial.println("thi:" + iTenHighMax);
// Serial.println("tlo:" + iTenLowMax);
if ((tempr <= iTemp) && (iTenHigh < iTenHighMax)){
digitalWrite(TEN_WIRE, HIGH);
displayData("H");
iTenHigh++;
iTenLow = 0;
}else{
digitalWrite(TEN_WIRE, LOW);
displayData("L");
iTenLow++;
if(iTenLow >= iTenLowMax)
iTenHigh = 0;
}
displayData("\r\n");
return (tempr >= (iTemp - 1)) and (tempr <= (iTemp + 10));
}
示例3: tempSensorsPrintInfo
/**
* \brief Prints all connected OneWire sensors with there index
and current temperature value.
*/
void tempSensorsPrintInfo(void){
uint8_t address[8];
float temp;
uint8_t deviceCount=sensors.getDeviceCount();
Serial.print("Found devices: ");
Serial.println(deviceCount);
Serial.println(" ");
sensors.requestTemperatures();
for(int i=0; i<deviceCount; i++){
Serial.print("Device: ");
Serial.println(i);
if(sensors.getAddress(address, i)){
temp=sensors.getTempC(address);
Serial.print("Temp: ");
Serial.print(temp);
Serial.println(" ");
//delay(100);
Serial.print("Resolution: ");
Serial.println(sensors.getResolution(address));
Serial.println("");
//delay(100);
}
}
}
示例4: setup
void setup() {
// Init display
mySerial.begin(9600); // set up serial port for 9600 baud
delay(500); // wait for display to boot up
// Setup DS1820 temp sensor
sensors.begin();
sensors.setResolution(Sensor1, 11);
sensors.setResolution(Sensor2, 11);
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - 11)); //750 for 12bit, 400 for 11bit, 220 for 10bit, 100 for 9bit
// calc by delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();
// Set next state i FSM
menu_FSM = M_PAGE1;
menu_last_state = M_PAGE1;
system_FSM = S_IDLE;
// **************** Set up display *******************
DisplayClear();
MenuShowTime = millis();
// **************** Set up RTC ***********************
Wire.begin();
rtc.begin();
//TimeDate(rtc.now(),dateTimeString,1);
//DateTime now = rtc.now();
// write on display
DisplayGoto(2,0);
mySerial.print("Version 0.9B");
// **************** Set up SD card *******************
pinMode(10, OUTPUT);
DisplayGoto(1,0);
mySerial.write("Init SD -> "); // clear display + legends
DisplayGoto(1,11);
// see if the card is present and can be initialized:
if (!SD.begin())
mySerial.write("Fail");
else
mySerial.write("OK");
delay(2000);
// ***************** Clear display ********************
DisplayClear();
}
示例5: doTout
void doTout() {
String vStr;
memset(tmpChr,0,sizeof(tmpChr));
if (hasTpwr>0) {
digitalWrite(hasTpwr, HIGH); // ow on
delay(5); // wait for powerup
}
ds18b20.requestTemperatures();
byte retry = 20;
float temp=0.0;
do {
temp = ds18b20.getTempCByIndex(0);
retry--;
delay(2);
} while (retry > 0 && (temp == 85.0 || temp == (-127.0)));
if (hasTpwr>0) {
digitalWrite(hasTpwr, LOW); // ow off
}
vStr = String("temp=") + String(temp,3);
vStr.toCharArray(tmpChr, vStr.length()+1);
}
示例6: temperatureJob
void temperatureJob() {
float gotTemp = 0;
Serial << "the device count is " << deviceCount << endl;
sensor.requestTemperatures(); // get all the tempratures first to speed up, moved up from getTemp()
for (int i =0; i < deviceCount; i++ ) {
gotTemp = sensor.getTempF(*deviceAddressArray[i]);
if (gotTemp < -195 ) continue;
Serial << "gotTemp() = " << i << " " << gotTemp << endl;
request.body = formatTempToBody(gotTemp, i);
// if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1 ) {
if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1) {
String mypath = String("/api/v1.6/variables/");
mypath.concat(ubivar[i]);
mypath.concat("/values");
Serial << "going to push "<< request.body << " to " << mypath << endl;
request.path = mypath;
http.post(request, response, headers);
if( debug ) Serial << "http body: " << request.body << endl;
Serial << " Did we reboot? I hope not ";
}
if( debug) debugSerial(i);
}
}
示例7:
float MXS1101::getTempC()
{
oneWire.reset();
_MXS1101.begin();
_MXS1101.requestTemperatures();
return _MXS1101.getTempCByIndex(0);
}
示例8: sprintf
void DS18B20_sample(){
#ifdef DEBUG_DS18B20_POLLER
DEBUG_1("Starting");
#endif
#ifdef DEBUG_DS18B20_POLLER
DEBUG_5("Requesting Temperatures");
#endif
char buf[25];
ds_sensors.requestTemperatures();
for (int i=0; i < ds_count; i++){
#ifdef DEBUG_DS18B20_POLLER
DEBUG_5("Logging DSB Pin");
#endif
sprintf(buf, "DS18B20.%d", i);
logMessage(buf, ds_sensors.getTempCByIndex(i), "Degrees/C");
#ifdef DEBUG_DS18B20_POLLER
DEBUG_5("Logged DSB Pin");
#endif
}
#ifdef DEBUG_DS18B20_POLLER
DEBUG_2("Requested Temperatures");
#endif
#ifdef DEBUG_DS18B20_POLLER
DEBUG_1("Finished");
#endif
}
示例9: sensorRoofTempdecic
/* Temperature Sensor */
long sensorRoofTempdecic(void)
{
long value = 0;
dallas_roof_sen.requestTemperatures();
value = dallas_roof_sen.getTempCByIndex(0);
return value;
}
示例10: loop
void loop(void)
{
delay(2000);
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// Loop through each device, print out temperature data
for(int i=0;i<numberOfDevices; i++)
{
// Search the wire for address
if(sensors.getAddress(tempDeviceAddress, i))
{
// Output the device ID
Serial.print("Temperature for device: ");
Serial.println(i,DEC);
// It responds almost immediately. Let's print out the data
printTemperature(tempDeviceAddress); // Use a simple function to print out the data
}
//else ghost device! Check your power requirements and cabling
}
}
示例11: setup
/**
* @brief arduino setup function
*/
void setup() {
Serial.begin(9600);
Display::Init();
if (RTC.get() == 0) {
// following line sets the RTC to the date & time this sketch was compiled
RTC.set(hhmmss());
}
setSyncProvider(RTC.get); // the function to get the time from the RTC
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(7);
dallastemp.begin(); // Inizialisieren der Dallas Temperature library
dallastemp.setWaitForConversion(false);
aqua.begin();
pinMode(BUTTON_PIN_1, INPUT_PULLUP);
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
// pinMode(BUTTON_PIN_3, INPUT_PULLUP);
// pinMode(BUTTON_PIN_4, INPUT_PULLUP);
}
示例12: readTempHumid
void readTempHumid()
{
temperatureSensor.requestTemperatures();
double tempCelcius = temperatureSensor.getTempCByIndex(0);
String toDrawTemp = doubleToString(tempCelcius, 2);
double humidityVoltage = (double) analogRead(5) / 1024 * REFERENCE_VOLTAGE;
double humidityPercentage = (humidityVoltage / REFERENCE_VOLTAGE - 0.16) / 0.0062;
double relativeHumidity = humidityPercentage / (1.0546 - 0.00216 * tempCelcius);
if(relativeHumidity > 100)
relativeHumidity = 100;
else if(relativeHumidity < 0)
relativeHumidity = 0;
String toDrawHumid = doubleToString(relativeHumidity, 2);
if(deviceStatus == TEMP_VIEW)
{
LCD.rectangle(81, 0, 320, 240, BLACK);
LCD.tText(7, 6, WHITE, "Temp(C): " + toDrawTemp + "C");
LCD.tText(7, 7, WHITE, "RH%: " + toDrawHumid + "%");
}
if(writeToSD)
{
String toWrite = toDrawTemp + "\t" + toDrawHumid + "\n";
LCD.appendString2File("Data", toWrite);
}
}
示例13: createAddressTable
/**
* \brief Creates a table with all sensors which are connected via OneWire.
*
* The table is created on the basis of a previous table which is stored
* in the EEPROM. This helps to have a consistent assignment of the sensor ID
* to the connected sensor. Otherwise this can change after a reset or if a
* sensor is removed.
*/
error_t createAddressTable(void){
uint8_t address[8];
tempSensorTable.size=0;
uint8_t index=0;
tempSensorTable_t eepromTable;
memset(&tempSensorTable,0,sizeof(tempSensorTable_t));
int8_t deviceCount=sensors.getDeviceCount();
for(int i=0; i<deviceCount; i++){
if(sensors.getAddress(address, i)){
memcpy(tempSensorTable.tableEntry[index].address,address,sizeof(address));
tempSensorTable.tableEntry[index].tempSensorID=i;
tempSensorTable.tableEntry[index].enabled=1; //default: send temp sensor value
++index;
}
}
tempSensorTable.size=index;
if(!loadAddressTableFromEEPROM(&eepromTable)){
//table found in EEPROM
mergeTables(&eepromTable, &tempSensorTable);
}
writeAddressTableToEEPROM(&tempSensorTable);
return ERR_NO_ERR;
}
示例14: sensor_setup
void sensor_setup(){
temp_sensor.begin();//initialize one wire sensor
temp_sensor.setResolution(insideThermometer, 9); //configure sensor parameters
#ifdef DEBUG_SENS
// report on finding the devices on the bus or not
if (!temp_sensor.getAddress(insideThermometer, 0)) softdebug.println("Unable to find address for Device 0");
else{
// report parasite power requirements
softdebug.print("Parasite power is: ");
if (temp_sensor.isParasitePowerMode()) softdebug.println("ON");
else softdebug.println("OFF");
sensors_temperature(); //print temperature for debugging
}
//print voltage sensor value for debugging
softdebug.print("Vin=");
softdebug.println(sensors_vin());
#endif //DEBUG_SENS
}
示例15: begin
void Thermometer::begin() {
if (!initialized) {
// Start up the library
sensors.begin();
sensors.setResolution(thermometerAddress, RESOLUTION);
initialized = true;
}
}