错误:“double”类型的操作数无效和“双”到二元“运算符^”
我正在尝试编写一段代码来根据 arduino nano 上记录的压力和温度计算高度。这是我的代码:
#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);
}
我不断收到错误:
exit status 1
invalid operands of types 'double' and 'double' to binary 'operator^'
我该如何解决这个问题?我是 arduino 和 C 的新手,希望得到任何帮助 谢谢
I am attempting to write a piece of code to calculate altitude from pressure and temperature recorded on an 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? I am new to arduino and C and would appreciate any help
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
^
是按位异或逻辑运算符。它仅适用于整数类型。如果您想将数字提高到一定幂,请使用 std::pow() 函数。
^
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.