[英]error: invalid operands of types 'double' and 'double' to binary 'operator^'
I am attempting to write a piece of code to calculate altitude from pressure and temperature recorded on an arduino nano.我正在尝试编写一段代码来根据 arduino nano 上记录的压力和温度计算高度。 This is my code:这是我的代码:
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
int temp = 0;
int pressure = 0;
int altitude = 0;
void setup() {
// put your setup code here, to run once:
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
bmp_temp->printSensorDetails();
}
void loop() {
// put your main code here, to run repeatedly:
sensors_event_t temp_event, pres_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pres_event);
temp = temp_event.temperature;
pressure = pres_event.pressure;
altitude = (((101.325/ (pressure/1000))^1/5.257)-1)*(temp +273.15))/0.0065;
Serial.print(temp);
Serial.print(",");
Serial.print(pressure)
Serial.print(",");
Serial.print(altitude);
}
I keep on getting the error:我不断收到错误:
exit status 1
invalid operands of types 'double' and 'double' to binary 'operator^'
How do I go about fixing this?我如何解决这个问题 go? I am new to arduino and C and would appreciate any help Thank you我是 arduino 和 C 的新手,希望得到任何帮助谢谢
^
is a bitwise XOR logic operator . ^
是按位异或 逻辑运算符。 It works only with integral types.它仅适用于整数类型。
If you want to raise a number to some power, use std::pow() function.如果你想提高一个数的某种幂,使用std::pow() function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.