int unsigned long time1=0;
int sw=10;
int led_pin=13;
int led[]={2,3,4,5,6,7,8,9};
int debounceDelay=20;
int val;
int i;
int j=7;
int direct=0;
void setup()
{
pinMode(led_pin,OUTPUT);
pinMode(sw,INPUT);
digitalWrite(sw,HIGH);
for(int i=0;i<8;i++)
{
pinMode(led[i],OUTPUT);
}
}
void loop()
{
if(millis()-time1>500)
{
time1-millis();
digitalWrite(led_pin,HIGH);delay(500);
digitalWrite(led_pin,LOW);delay(500);
}
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(1000);
if(j==0)
j=7;
else
j--;
}
else
{
digitalWrite(led[j],HIGH);
delay(300);
if(j==7)
j=0;
else
j++;
}
}
沒有留言:
張貼留言