gpt4 book ai didi

c++ - 无法理解arduino示例代码的语法

转载 作者:行者123 更新时间:2023-11-28 06:28:19 25 4
gpt4 key购买 nike

我正在尝试理解为 MPU-9150 加速器/陀螺仪/磁力计提供的示例代码。我想它是基本的,但我以前没见过。

double dT = ( (double) MPU9150_readSensor(MPU9150_TEMP_OUT_L,MPU9150_TEMP_OUT_H) + 12412.0) / 340.0;
Serial.print(dT);

MPU9150_readSensor 涉及使用两个地址从传感器接收 16 位整数的函数。我不明白的是 ((double) MPU....,为什么需要这个,它不是已经被声明为 double 了吗?

非常感谢

亚历克斯

最佳答案

MPU9150_readSensor() 返回一个 int

我们希望编译器理解您有意从函数中获取 double 值。

这就是你输入 cast 的原因。

引用:http://playground.arduino.cc/Main/MPU-9150

关于c++ - 无法理解arduino示例代码的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28136381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com