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