const int sw=10;
const int led[]={2,3,4,5,6,7,8,9};
const int debounceDelay=20;
int val;
int i;
int j=7;
int direct=0;
void setup() {
pinMode(sw,INPUT_PULLUP);
for(i=0;i<8;i++)
{
pinMode(led[i],OUTPUT);
}
}
void loop() {
val=digitalRead(sw);
if(val==LOW)
{
delay(debounceDelay);
while(digitalRead(sw)==LOW)
;
direct=!direct;
}
for(i=0;i<8;i++)
{
digitalWrite(led[i],LOW);
}
if(direct==0)
{
digitalWrite(led[j],HIGH);
delay(500);
j=j+1;
if(j==8)
j=0;
}
else
{
digitalWrite(led[j],HIGH);
delay(500);
j=j-1;
if(j==0)
j=7;
}
}
沒有留言:
張貼留言