本文整理汇总了C++中DallasTemperature::getTempC方法的典型用法代码示例。如果您正苦于以下问题:C++ DallasTemperature::getTempC方法的具体用法?C++ DallasTemperature::getTempC怎么用?C++ DallasTemperature::getTempC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DallasTemperature
的用法示例。
在下文中一共展示了DallasTemperature::getTempC方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
示例2: updateTemperature
void updateTemperature()
{
sensor.requestTemperatures();
tempInCelsius = (int) (sensor.getTempC(devAddr)*10);
digitValues[0] = tempInCelsius / 100;
digitValues[1] = (tempInCelsius % 100) / 10;
digitValues[2] = tempInCelsius % 10;
for (int i = 0; i < N-1; i++)
display.writeDigit(i, digitValues[i]);
}
示例3: tempSensorRead
/**
* \brief Reads all connected temperature sensors.
*
* Table: DS18B20 Conversion Times and Resolution Settings
* Resolution 9 bit 10 bit 11 bit 12 bit
* Conversion Time (ms) 93.75 187.5 375 750
* LSB (°C) 0.5 0.25 0.125 0.0625
* See also: http://www.maximintegrated.com/en/app-notes/index.mvp/id/4377
*/
error_t tempSensorRead(void){
sensors.requestTemperatures();
for(int i=0; i<tempSensorTable.size; i++){
if(sensors.isConnected(tempSensorTable.tableEntry[i].address)){
tempSensorTable.tableEntry[i].sensorValue=sensors.getTempC(tempSensorTable.tableEntry[i].address);
}
else{
tempSensorTable.tableEntry[i].sensorValue=999;
}
}
return ERR_NO_ERR;
}
示例4: printTemperature
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
// method 1 - slower
//Serial.print("Temp C: ");
//Serial.print(sensors.getTempC(deviceAddress));
//Serial.print(" Temp F: ");
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
// method 2 - faster
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}
示例5: readTemperatureF
float Thermometer::readTemperatureF() {
float tempC = (float)DEVICE_DISCONNECTED;
this->lastReadingError = true;
sensors.requestTemperatures();
tempC = sensors.getTempC(thermometerAddress);
if (tempC == (float)DEVICE_DISCONNECTED) {
this->lastReadingError = true;
} else {
this->lastReadingError = false;
}
return DallasTemperature::toFahrenheit(tempC);
}
示例6: sensors_temperature
int sensors_temperature(){
// call temp_sensor.requestTemperatures() to issue a global temperature request to all devices on the bus
temp_sensor.requestTemperatures(); // Send the command to get temperatures
// call temp_sensor.getTempC to read temperature in degrees Celsius from the device
int temperature =(int) temp_sensor.getTempC(insideThermometer);
#ifdef DEBUG_SENS
softdebug.println();
softdebug.print("Temp C: ");
softdebug.println(temperature);
#endif
return temperature;
}
示例7: setup
void setup()
{
fsmState = EDIT_TIME_MODE;
// initialize thermometer
sensor.begin();
sensor.setWaitForConversion(true);
sensor.getAddress(devAddr, 0);
sensor.requestTemperatures();
tempInCelsius = (int) (sensor.getTempC(devAddr)*10);
// initialize buttons
buttonA.setClickTicks(250);
buttonA.setPressTicks(600);
buttonA.attachLongPressStart(longPressA);
buttonA.attachClick(singleClickA);
buttonA.attachDoubleClick(doubleClickA);
buttonB.setClickTicks(250);
buttonB.setPressTicks(600);
buttonB.attachClick(singleClickB);
buttonB.attachDoubleClick(doubleClickB);
buttonB.attachLongPressStart(longPressB);
// initialize serial
Serial.begin(115200);
// initialize rtc
setSyncProvider(RTC.get);
setSyncInterval(1);
if(timeStatus()!= timeSet)
{
Serial.println("Unable to sync with the RTC");
fsmState = ERROR_MODE;
} else
{
Serial.println("RTC has set the system time");
}
// default alarm settings, 08:30, disabled
pinMode(ALARM_PIN, INPUT_PULLUP);
}
示例8: loop
void loop() {
File dataFile;
//String dataString;
//char dataToSD[40];
//String timeString;
char tempstring[10]; // create string arrays
//float temp;
static int WaitingForTemp = 0;
//int readCount;
DateTime now; // = rtc.now();
static int nowriting = 0;
delay(1000);
switch(system_FSM) {
case S_IDLE:
//Read time from RTC
now = rtc.now();
if(now.minute() % 11 == 0)
nowriting = 0;
//Trigger state change
if(WaitingForTemp == 1){
if (millis() - lastTempRequest >= delayInMillis) // waited long enough??
system_FSM = S_READ_SENS;
}
if(WaitingForTemp == 0) {
system_FSM = S_TRIG_TEMP;
if(now.minute() % 10 == 0 || nowriting == 0)
system_FSM = S_WRITE_SD;
nowriting = 1;
}
break;
case S_TRIG_TEMP:
// Trig async reading of DS1820 temp sensor
sensors.requestTemperatures();
// remember time of trigger
lastTempRequest = millis();
WaitingForTemp = 1;
system_FSM = S_IDLE;
break;
case S_READ_SENS:
//read value of sensors
SensorData.sensor1 = sensors.getTempC(Sensor1);
SensorData.sensor2 = sensors.getTempC(Sensor2);
//SensorData.sensor1 = sensors.getTempC(Sensor1);
//SensorData.sensor1 = sensors.getTempC(Sensor1);
//SensorData.sensor1 = sensors.getTempC(Sensor1);
WaitingForTemp = 0;
system_FSM = S_IDLE;
/*
if(readCount == 0)
system_FSM = S_WRITE_SD;
else
system_FSM = S_IDLE;
readCount++;
*/
break;
case S_WRITE_SD:
// Read time and date from RTC
TimeDate(rtc.now(),dateTimeString,1);
// Open datafile
dataFile = SD.open("templog.txt", FILE_WRITE);
// Write values to SD card
if (dataFile) {
dataFile.print(dateTimeString);
dataFile.print(";");
dataFile.print(SensorData.sensor1);
dataFile.print(";");
dataFile.println(SensorData.sensor2);
dataFile.close();
}
// state change to IDLE
system_FSM = S_IDLE;
break;
default:
system_FSM = S_IDLE;
}
switch(menu_FSM) {
case M_PAGE1:
if(menu_FSM !=menu_last_state) {
DisplayClear();
mySerial.write("Time"); // clear display + legends
MenuShowTime = millis();
}
now = rtc.now();
DisplayGoto(1,0);
mySerial.write("Time"); // clear display + legends
DisplayGoto(1,8);
TimeDate(now,dateTimeString,2);
mySerial.print(dateTimeString);
//.........这里部分代码省略.........
示例9: main
int main(void) {
Config32MHzClock(); // Setup the 32MHz Clock. Should really be using 2MHz...
// Setup output and input ports.
LEDPORT.DIRSET = 0xFF;
LEDPORT.OUT = 0xFF;
AD9835_PORT.DIRCLR = 0x40;
PORTC.DIRSET = 0x04;
// Start up the timer.
init_timer();
sensors.begin();
sensors.requestTemperatures();
// Wait a bit before starting the AD9835.
// It seems to take a few hundred ms to 'boot up' once power is applied.
_delay_ms(500);
// Configure the AD9835, and start in sleep mode.
AD9835_Setup();
AD9835_Sleep();
// Setup the AD9835 for our chosen datamode.
TX_Setup();
AD9835_Awake();
// Broadcast a bit of carrier.
_delay_ms(1000);
TXString("Booting up...\n"); // Kind of like debug lines.
// Start up the GPS RX UART.
init_gps();
// Turn Interrupts on.
PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm;
sei();
sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data.
//TXString("GPS Active, Interrupts On.\n");
int found_sensors = sensors.getDeviceCount();
//sprintf(tx_buffer,"Found %u sensors.\n",found_sensors);
// TXString(tx_buffer);
unsigned int counter = 0; // Init out TX counter.
while(1){
// Identify every few minutes
if ((counter%30 == 0)&&(data_mode != FALLBACK)) TXString("DE VK5VZI Project Horus HAB Launch - projecthorus.org \n");
// Read ADC PortA pin 0, using differential, signed input mode. Negative input comes from pin 1, which is tied to ground. Use VCC/1.6 as ref.
uint16_t temp = readADC();
float bat_voltage = (float)temp * 0.001007572056668* 8.5;
floatToString(bat_voltage,1,voltString);
// Collect GPS data
gps.f_get_position(&lat, &lon);
sats = gps.sats();
if(sats>2){LEDPORT.OUTCLR = 0x80;}
speed = gps.f_speed_kmph();
altitude = (long)gps.f_altitude();
gps.crack_datetime(0, 0, 0, &time[0], &time[1], &time[2]);
floatToString(lat, 5, latString);
floatToString(lon, 5, longString);
sensors.requestTemperatures();
_intTemp = sensors.getTempC(internal);
_extTemp = sensors.getTempC(external);
if (_intTemp!=85 && _intTemp!=127 && _intTemp!=-127 && _intTemp!=999) intTemp = _intTemp;
if (_extTemp!=85 && _extTemp!=127 && _extTemp!=-127 && _extTemp!=999) extTemp = _extTemp;
if(data_mode != FALLBACK){
// Construct our Data String
sprintf(tx_buffer,"$$DARKSIDE,%u,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d,%d,%s",counter++,time[0], time[1], time[2],latString,longString,altitude,speed,sats,intTemp,extTemp,voltString);
// Calculate the CRC-16 Checksum
char checksum[10];
snprintf(checksum, sizeof(checksum), "*%04X\n", gps_CRC16_checksum(tx_buffer));
// And copy the checksum onto the end of the string.
memcpy(tx_buffer + strlen(tx_buffer), checksum, strlen(checksum) + 1);
}else{
// If our battery is really low, we don't want to transmit much data, so limit what we TX to just an identifier, battery voltage, and our position.
sprintf(tx_buffer, "DE VK5VZI HORUS8 %s %s %s %ld", bat_voltage, latString, longString,altitude);
}
// Blinky blinky...
LEDPORT.OUTTGL = 0x20;
//.........这里部分代码省略.........
示例10: loop
/*
* Main Loop
*/
void loop() {
wdt_reset();
mD.vals.uslCount++; //Increment main datarecord count
AccelerometerScaled Ascaled = accel.ReadScaledAxis(); //Get Scaled Accelerometer
AccelerometerRaw Araw = accel.ReadRawAxis(); //Get Raw Accelerometer
MagnetometerScaled Mscaled = compass.ReadScaledAxis(); //Get Scaled Magnetometer
MagnetometerRaw Mraw = compass.ReadRawAxis(); //Get Raw Magnetometer
LGgyro.read(); //Get Gyro
// offset compass by hard iron
Mraw.XAxis += 40;
Mraw.YAxis += 261;
Mraw.ZAxis += 54;
//write Acc, Mag, & Gyro values to record
float AxisGs = Ascaled.XAxis;
mD.vals.AcXPayload = AxisGs * 100;
AxisGs = Ascaled.YAxis;
mD.vals.AcYPayload = AxisGs * 100;
AxisGs = Ascaled.ZAxis;
mD.vals.AcZPayload = AxisGs * 100;
mD.vals.MgXPayload = Mscaled.XAxis;
mD.vals.MgYPayload = Mscaled.YAxis;
mD.vals.MgZPayload = Mscaled.ZAxis;
mD.vals.GyXPayload = LGgyro.g.x;
mD.vals.GyYPayload = LGgyro.g.y;
mD.vals.GyZPayload = LGgyro.g.z;
//Perform tilt compensation calculation save to record
sixDOF.compCompass(Mraw.XAxis, -Mraw.YAxis, -Mraw.ZAxis, Araw.XAxis, Araw.YAxis, Araw.ZAxis, true);
float compHeading = sixDOF.atan2Int(sixDOF.xAxisComp(), sixDOF.yAxisComp());
compHeading = compHeading /100;
if (compHeading < 0 ) {
compHeading = abs(compHeading);
} else {
compHeading = 180 - compHeading + 180;
}
mD.vals.CmpssPayload = compHeading;
//get BMP085 values save to record
dps.getTemperature(&TmpPayloadFULL);
dps.getPressure(&mD.vals.PressurePayload);
mD.vals.TmpPayload = (int16_t)(TmpPayloadFULL);
mD.vals.TmpExternal = (int16_t)(sensors.getTempC(outsideThermometer)* 10);
sensors.requestTemperaturesByAddress(outsideThermometer); // Send the command to get temperatures
//get GPS data
byte lcount = 0; //reset a loop counter
while (!NEWGPSDATA && lcount++ < 255) { //Exit the loop if we have new data or have been round it a number of times
NEWGPSDATA = feedgps();
}
if (NEWGPSDATA) { //We have new GPS data, get all of the fields we need.
int tmp_year = 0;
gps.crack_datetime(&tmp_year, &mD.vals.month, &mD.vals.day,&mD.vals.hour, &mD.vals.minute, &mD.vals.second, &mD.vals.hundredths, &mD.vals.age);
mD.vals.year = tmp_year - 2000;
if (gps.altitude() != TinyGPS_HJOE::GPS_INVALID_ALTITUDE && gps.altitude() >= 0) {
gps.get_position(&mD.vals.iLat, &mD.vals.iLong, &mD.vals.age);
mD.vals.iAlt = gps.altitude();
mD.vals.iAngle = gps.course();
mD.vals.iHspeed = gps.speed();
mD.vals.bSats = gps.satellites();
mD.vals.ihdop = gps.hdop();
}
SET_LED_Status(SET_LED_BLUE,0); //Flash blue to show we are getting GPS data
} else {
SET_LED_Status(SET_LED_GREEN,0); //Flash Green to show that we are looping but not getting GPS data
}
if(ETSerialIn.receiveData()){
}
//flip flop between I2C's to avoid both on one loop
if (SENDWIRE && (millis() - elapseSIM900) > WAIT_SIM900) {
mD.vals.tCount++;
ETI2Cout.sendData(I2C_SLV_SIM900_ADDRESS);
elapseSIM900 = millis();
}
if (!SENDWIRE && (millis() - elapseNTXB) > WAIT_NTXB) {
mD.vals.tCount++;
ETI2Cout.sendData(I2C_SLV_NTXB_ADDRESS);
elapseNTXB = millis();
//get I2C_SLV_SIM900_ADDRESS data
}
writeSDData(); //Write the data record to the SD card
SET_LED_Status(SET_LED_OFF,0); //turn off the LED
NEWGPSDATA = false; //Reset the New GPS Data flag
SENDWIRE = !SENDWIRE; //Flipflop this
}
示例11: update18B20Temp
void update18B20Temp(DeviceAddress deviceAddress, double &tempC)
{
tempC = sensors.getTempC(deviceAddress);
}
示例12: loop
void loop()
{
delay(1000);
sensors.requestTemperatures();
float tempO = sensors.getTempC(outsideThermometer);
float tempI = sensors.getTempC(insideThermometer);
if (tempO == -127.00) {
Serial.print("Error getting temperature");
} else {
// Serial.print(" C: ");
// Serial.println(tempC);
}
// build the timestamp
chronodot.readTimeDate();
String timeStamp = "";
int yearZ = chronodot.timeDate.year;
timeStamp += yearZ;
timeStamp += "-";
int monthZ = chronodot.timeDate.month;
if (monthZ < 10) timeStamp += "0";
timeStamp += monthZ;
timeStamp += "-";
int dayZ = chronodot.timeDate.day;
if (dayZ < 10) timeStamp += "0";
timeStamp += dayZ;
timeStamp += ",";
int hourZ = chronodot.timeDate.hours;
if (hourZ < 10) timeStamp += "0";
timeStamp += hourZ;
timeStamp += ":";
int minZ = chronodot.timeDate.minutes;
if (minZ < 10) timeStamp += "0";
timeStamp += minZ;
timeStamp += ":";
int secZ = chronodot.timeDate.seconds;
if (secZ < 10) timeStamp += "0";
timeStamp += secZ;
timeStamp += ":";
// open the log file and append the data row.
File dataFile = SD.open("HAPPy_data.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(timeStamp);
dataFile.print(",");
dataFile.print(tempO);
dataFile.print(",");
dataFile.print(tempI);
dataFile.println(",");
// close the log file...
dataFile.close();
// print to the serial port too:
Serial.println(timeStamp);
Serial.print("Outside Temperature: ");
Serial.println(tempO);
Serial.print("Inside Temperature: ");
Serial.println(tempI);
Serial.println();
}
// if the file isn't open, pop up an error:
else {
Serial.println("Shizzle! Error opening log file...");
}
}