问题描述
我正在使用我朋友的代码建造一个气象站.但是,他是 Arduino 的旧版本,我无法弄清楚原因.我是编程新手,所以我不知道'dht' 不命名类型"是什么意思?我正在使用 Arduino 1.04,我的朋友在 Arudino 0022 上编写了他的气象站.我的问题是,为什么我的验证无法编译?我做错了什么?
I am building a weather station using my friend's code. However, he an older verison of Arduino and I'm having trouble figuring out why. I am new to programming, so I don't know what "'dht' does not name a type" means? I'm using Arduino 1.04 and my friend coded his weather station on Arudino 0022. My question is, why isn't my verification able to compile? What am I doing incorrectly?
这是我的代码:
#include <dht.h>
dht DHT;
#define DHT22_PIN 2
#include <Wire.h>
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 3; // Oversampling Setting
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
short temperature;
long pressure;
void setup()
{
pinMode(2, INPUT);
Wire.begin();
bmp085Calibration();
Serial.begin(115200);
analogReference(INTERNAL);
}
void loop() {
// READ DATA
float bat_read=analogRead(6);
//bat_read = analogRead(BAT_voltage);
float chk = DHT.read22(DHT22_PIN);
// DISPLAY DATA
Serial.print(bat_read, DEC);
Serial.print(", ");
Serial.print(DHT.humidity, 2);
Serial.print(", ");
temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
Serial.print(temperature, DEC);
Serial.print(", ");
Serial.println(pressure, DEC);
delay(1000);
}
错误是:
error: 'dht' does not name a type
sketch_jul05a.ino: In function 'void loop()': error: 'DHT' was not declared in this scope
推荐答案
关于你应该的特定错误
'dht' 没有命名类型
这意味着您的 dht
这个词不在编译器可以理解的地方.
That means you have the word dht
that is not at a place where the compiler could understand what you mean.
如何将其更改为类型?
您不想将其更改为类型,而是想解决您遇到的编译问题.
You do not want to change it into a type, you want to solve the compiling issue you're getting.
类型是什么意思?
您应该阅读 主题.类型是一种规则,它限制您编写连贯的代码.
You should read the K&R on the subject. A type is a rule that constraints you into making code that is coherent.
你应该在你的问题中复制你得到的完整错误,以便我们更好地帮助你.
You should copy in your question the full error you're getting, for us to better help you.
让我们假设错误在以下行:
Let's assume the error is on the following line:
#include <dht.h>
dht DHT;
编译器不知道什么是 dht
,因为它以前从未见过它被定义过.我假设, dht.h
应该是一个需要包含 dht
类型定义的头文件.您应该查看文件系统中是否有 dht.h
,并将其推送到您的草图目录中.最后把#include
改成#include "dht.h"
,这样它就查找dht.h
在您的本地目录中.
The compiler does not know what is the dht
, as it has never seen that being defined before. I assume, dht.h
shall be a header to be included that needs should contain dht
type definition. You should look if you have dht.h
in your filesystem, and push it in your sketch's directory. And finally change the #include <dht.h>
into #include "dht.h"
, so it looks up the dht.h
in your local directory.
很抱歉,除了我刚才所说的之外,我认为我无法帮助您.问题是你不明白我在告诉你什么来解决你的问题,向你解释它会给你上一堂 C 编程课.所以你应该首先开始阅读K&R,去一些C/C++/Arduino编程课程(可能在您当地的黑客空间?),和/或请您的朋友帮助您并向您解释正在发生的事情.
I'm sorry I don't think I can't help you here more than what I just said. The problem is that you don't understand what I'm telling you to solve your problem, and explaining it to you would be giving you a C programming lesson. So you should first begin to read the K&R, go to some C/C++/Arduino programing courses (maybe in your local hackerspace?), and/or ask your friend to help you out and explaining to you what is happening.
这篇关于Arduino 中的类型错误是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!