错误:“double”类型的操作数无效和“双”到二元“运算符^”

发布于 2025-01-13 09:07:32 字数 1547 浏览 0 评论 0原文

我正在尝试编写一段代码来根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2025-01-20 09:07:32

^ 是按位异或逻辑运算符。它仅适用于整数类型。

如果您想将数字提高到一定幂,请使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文