【求助】LED灯简单程序
一个红灯,一个绿灯,当光线>X时,红灯亮,在光线>X时,绿灯亮新手求助,谢谢各位大佬!
请问该如何设计此程序?谢谢谢谢 unsigned charRedLight=12;
unsigned char GreenLight=13;
#defineX 512
int SensorValue = 0;// variable to store the value coming from the sensor
void setup() {
// put your setup code here, to run once:
pinMode(RedLight, OUTPUT);
pinMode(GreenLight, OUTPUT);
}
void loop() {
SensorValue = analogRead(sensorPin);
if( SensorValue>X )
{digitalWrite(RedLight, HIGH);
digitalWrite(GreenLight, LOW);
}
else
{ digitalWrite(RedLight, LOW);
digitalWrite(GreenLight, HIGH);
}
页:
[1]