标题: 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);        // 中断设置函数,每 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.51hei.com/bbs/) Powered by Discuz! X3.1