標題: ARDUINO定時器中斷實驗 [打印本頁]

作者: S.H.M    時間: 2019-8-2 19:41
標題: ARDUINO定時器中斷實驗
#include <MsTimer2.h>               //定時器庫的 頭文件
int LED1=13;
int LED2=9;

void setup() {
  // put your setup code here, to run once:
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

MsTimer2::set(500, dongzuo);        // 中斷設(shè)置函數(shù),每 500ms 進入一次中斷
  MsTimer2::start();                //開始計時
}
void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(LED1,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
delay(1000);
}
void dongzuo()
{
  /*
static boolean out=HIGH;
digitalWrite(LED2,out);
out=!out;
*/
digitalWrite(LED2,HIGH);
delay(100);
digitalWrite(LED2,LOW);
delay(100);




  }



作者: tyrl800    時間: 2019-9-1 21:02
用TIMERONE庫更簡單喲




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1