int btn=2;
int led[]={3,4,5,6};
int i;
int j=0;
int value;
int direct;
void setup()
{
pinMode(btn,INPUT);
for(i=0;i<4;i++)
{
pinMode(led[i],OUTPUT);
}
}
void loop()
{
for(i=0;i<4;i++)
{
digitalWrite(led[i],LOW);
}
value=digitalRead(btn);
if(value==LOW)
{
delay(20);
while(digitalRead(btn)==LOW);
direct=direct^1;
}
if(direct==0)
{
digitalWrite(led[j],HIGH);
delay(1000);
if(j==3)
j=0;
else
j++;
}
else if(direct==1)
{
digitalWrite(led[j],HIGH);
delay(1000);
if(j==0)
j=3;
else
j--;
}
}
沒有留言:
張貼留言