就这个问题,为什么我用c语言中设置一个变量在if语句中不能实现呢?
程序如下:
int redled=10;
int yellowled=9;
int greenled=8;
int redpin=7;
int yellowpin=6;
int greenpin=5;
int red;
int yellow;
int green;
int i;
void setup()
{
i=0;
pinMode(redled,OUTPUT);
pinMode(yellowled,OUTPUT);
pinMode(greenled,OUTPUT);
pinMode(redpin,INPUT);
pinMode(yellowpin,INPUT);
pinMode(greenpin,INPUT);
}
void loop()
{
red=digitalRead(redpin);
if(red==LOW&i==0)
{i=i+1;digitalWrite(redled,LOW);}
else
{ digitalWrite(redled,HIGH);}
yellow=digitalRead(yellowpin);
if(yellow==LOW&i==0)
{i=i+1;digitalWrite(yellowled,LOW);}
else
{ digitalWrite(yellowled,HIGH);}
green=digitalRead(greenpin);
if(green==LOW&i==0)
{i=i+1;digitalWrite(greenled,LOW);}
else
{ digitalWrite(greenled,HIGH);}
}
请大神支招{:soso_e183:} |