int sensorPin=A0;
void setup(){
Serial.begin(9600);
for(int x=2;x<5;x++){
pinMode(x,OUTPUT);
digitalWrite(x,LOW);
}
}
void loop(){
sensorVal=analogRead(sensorPin);
Serial.print(senseorVal);
Serial.print('ADC,');
float voltage=(sensorVal/1024.0)*5;
Serial.print(voltage);
Serial.print('volts,');
float temperature=(voltage- .5)*5;
Serial.print(temperature);
Serial.printnl('degrees C');
if(temperature<baselineTemp){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
if(temperature>=baselineTemp+2 && temperature<=baselineTemp+4){
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
if(temperature>=baselineTemp+4 && temperature<=baselineTemp+6){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}
if(temperature>baselineTemp+6){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
}
各位帮忙看一看我这个程序baselineTemp应该怎么指定?还有看看哪里有错的,我是看RS的Arduino入门视频记下来的,但是视频不清,有一些不能看清楚 |