|
本人小白一枚 白痴问题请谅解
使用三个18B20温度传感器 控制三个电机 现在的问题是只有一组管用(传感器到达设置温度后风扇停止),其他两组风扇一直在转个不停 是不是缺少什么语句
我用的是米思齐码的程序
翻译的代码如下
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire_A0(A0);
DallasTemperature sensors_A0(&oneWire_A0);
DeviceAddress insideThermometer;
OneWire oneWire_A2(A2);
DallasTemperature sensors_A2(&oneWire_A2);
OneWire oneWire_A3(A3);
DallasTemperature sensors_A3(&oneWire_A3);
float ds18b20_A0_getTemp(int w) {
sensors_A0.requestTemperatures();
if(w==0) {
return sensors_A0.getTempC(insideThermometer);
}
else {
return sensors_A0.getTempF(insideThermometer);
}
}
float ds18b20_A2_getTemp(int w) {
sensors_A2.requestTemperatures();
if(w==0) {
return sensors_A2.getTempC(insideThermometer);
}
else {
return sensors_A2.getTempF(insideThermometer);
}
}
float ds18b20_A3_getTemp(int w) {
sensors_A3.requestTemperatures();
if(w==0) {
return sensors_A3.getTempC(insideThermometer);
}
else {
return sensors_A3.getTempF(insideThermometer);
}
}
void setup(){
sensors_A0.getAddress(insideThermometer, 0);
sensors_A0.setResolution(insideThermometer, 9);
pinMode(8, OUTPUT);
sensors_A2.getAddress(insideThermometer, 0);
sensors_A2.setResolution(insideThermometer, 9);
sensors_A3.getAddress(insideThermometer, 0);
sensors_A3.setResolution(insideThermometer, 9);
pinMode(6, OUTPUT);
}
void loop(){
if (ds18b20_A0_getTemp(0) < 26) {
digitalWrite(8,HIGH);
} else {
digitalWrite(8,LOW);
}
if (ds18b20_A2_getTemp(0) < 26) {
pinMode(A5, OUTPUT);
digitalWrite(A5,HIGH);
} else {
pinMode(A5, OUTPUT);
digitalWrite(A5,LOW);
}
if (ds18b20_A3_getTemp(0) < 26) {
digitalWrite(6,HIGH);
} else {
digitalWrite(6,LOW);
}
}
|
|