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