程序:
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 3//DHT11温湿度传感器对应UNO的引脚
unsigned long previousMillis = 0;//记录Arduino上一时刻运行的时间
String comdata = "";
char varW_Temperature = 0,varW_Humidity=0;
void setup(){
Serial.begin(9600);
pinMode(12,INPUT);
pinMode(13,INPUT);
pinMode(2,INPUT);//左边
pinMode(4,INPUT);//右边
}
void loop()
{
//蓝牙遥控模式
while (Serial.available() > 0)
{
comdata += char(Serial.read());
delay(2);
}
if (comdata.length() > 0)
{
switch(comdata[0])
{
case 0x00:{GoStop();}break;//收到app发来00,小车停止
case 0x01:{GoAhead();}break;//收到app发来01,小车前进
case 0x02:{GoBehind();}break;//收到app发来02,小车后退
case 0x03:{GoLeft();}break;//收到app发来03,小车左行
case 0x04:{GoRight();}break;//收到app发来04,小车右行
case 0x08:{Serial.write(varW_Temperature);Serial.write(varW_Humidity);}break;//把数据发送到app
default:{GoStop();}//默认停止
}
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 2000) //2000ms发送一次数据
{
int chk = DHT11.read(DHT11PIN);
varW_Temperature = (float)DHT11.temperature;//DHT11的温度值
varW_Humidity = (float)DHT11.humidity;//DHT11的湿度值
previousMillis = currentMillis;
}
}
void GoAhead()//前进
{
analogWrite(6,100);//左前
analogWrite(10,0);//右前
analogWrite(5,0);//左后
analogWrite(9,100);//右后
}
void GoBehind()//后退
{
analogWrite(6,0); //左前
analogWrite(10,100); //右前
analogWrite(5,100); //左后
analogWrite(9,0);//右后
}
void GoLeft()//左转
{
analogWrite(6,0); //左前
analogWrite(10,0);//右前
analogWrite(5,0); //左后
analogWrite(9,100);//右后
}
void GoRight()//右转
{
analogWrite(6,100); //左前
analogWrite(10,0); //右前
analogWrite(5,0); //左后
analogWrite(9,0);//右后
}
void GoStop()
{
analogWrite(6,0); //左前
analogWrite(10,0); //右前
analogWrite(5,0); //左后
analogWrite(9,0);//右后
}
错误信息:
Arduino:1.6.7 (Windows 10), 开发板:"Arduino/Genuino Uno"
GetFileAttributesEx D:\Arduino\libraries\Dht11\dht11.cpp D:\Arduino\libraries\Dht11\dht11.h: The filename, directory name, or volume label syntax is incorrect.
编译有误。
报告将会包含更多的信息
"在编译时,输出详细信息"
在 文件>首选项 中启用
|