这段代码是做一个简单的rgb led温度计。我遇到的问题是我有三个颜色的温度层,而我的语法中的某些东西使它只看第一个逻辑门。代码如下所示。
// code by luke aka lazerfire15
const int temp= (A0);
int (red)=(2);
int (green)=(3);
int (blue)=(4);
int (tempread); //holds a value for the temp read
void setup()
{
pinMode (red,OUTPUT); //set inputs and outputs
pinMode (green,OUTPUT);
pinMode (blue,OUTPUT);
pinMode (temp,INPUT);
}
void loop()
{
tempread=(analogRead(temp)/(2.05)); // i used serial print here to test the temp sensor
analogRead(temp);
delay (100);
if ((tempread) >= (50) && (tempread) < (74)) {
pinMode(blue,HIGH);
}
else if ((tempread) >= (74) && (tempread) < (76)) {
pinMode(green,HIGH);
}
else if ((tempread) >= (76)) {
pinMode(red,HIGH);
}
}