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