简体   繁体   English

错误:二进制“operator^”的“double”和“double”类型的无效操作数

[英]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.

相关问题 'double' 和 'int' 类型的无效操作数到二进制 'operator%' - invalid operands of types 'double' and 'int' to binary 'operator%' 类型&#39;float()&#39;和&#39;double&#39;到二进制&#39;operator &lt;&#39;的无效操作数void loop() - invalid operands of types 'float()' and 'double' to binary 'operator<' void loop() 错误消息:“float”和“int”类型的无效操作数转换为二进制“operator%” - Error Message : Invalid operands of types 'float' and 'int' to binary 'operator%' 编译错误:'float' 和 'float' 类型的无效操作数到二进制 'operator^' - Compilation error: invalid operands of types 'float' and 'float' to binary 'operator^' arduino,错误:二进制“ operator +”类型为“ char [14]”和“ char [5]”的无效操作数 - arduino, error: invalid operands of types 'char [14]' and 'char [5]' to binary 'operator+' 如何解决 Arduino 程序中的“无效类型操作数”? - How to resolve "invalid operands of types" in an Arduino program? 如何解决:错误:“ operator =”不匹配(操作数类型为“ Estado”和“ Estado *”) - How to fix: error: no match for 'operator=' (operand types are 'Estado' and 'Estado*') 写一个双倍的EEPROM - Write a double to EEPROM sscanf双引号 - sscanf with double quotes 检查双“d &lt;0”是否可以? - Is it okay to check a double “d < 0”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM