const int ledPin = 11;
const int ledPin2 = 13;
int button = 2;
int ledState = LOW, ledState2 = LOW; //存放LED開或關的狀態
int buttonState=0; //存放按鈕的狀態
long interval = 1000;
long interval2 = 500;
int old_buttonState = 0; // 存放按鈕上一次的狀態
void blink();
void print();
TimedAction blinkAction = TimedAction(interval,blink);
TimedAction printAction = TimedAction(interval2,print);
void setup()
{
pinMode(ledPin,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(button,INPUT);
}
void loop()
{
blinkAction.check();
printAction.check();
}
void blink()
{
if(ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin,ledState);
}
void print()
{
if(ledState2 == LOW)
ledState2 = HIGH;
else
ledState2 = LOW;
digitalWrite(ledPin2,ledState2);
}
請問裡面有兩個活動1個LED每一秒閃一次,另一個LED每0.5秒閃一次,我現在要在裡面加按鈕,按下去要交換活動,請問如何加在裡面 謝謝
更新1:
是的交換閃爍的週期!