int add = 2;
int num;
boolean flag=1;
unsigned long time;
unsigned long time1;
void setup()
{
for (int i = 2; i < 10; i++)
{
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
pinMode(11, INPUT);
digitalWrite(11, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(11) == LOW)
{
delay(20);
while (digitalRead(11) == LOW);
num++;
Serial.println(num);
if (num % 2 == 0)
flag = 1;
else
flag = 0;
}
if (millis() - time1 >= 1000)
{
time1=millis();
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
}
if (millis() - time > 500)
{
if (flag)
{
digitalWrite(add, HIGH);
delay(500);
digitalWrite(add, LOW);
add++;
if (add > 9)
add = 2;
}
else if (flag == 0)
{
digitalWrite(add, HIGH);
delay(300);
digitalWrite(add, LOW);
add--;
if (add < 2)
add=9;
}
}
}
沒有留言:
張貼留言