ESP8266 Timer
http://www.it610.com/article/5312935.htm
停止定时器
os_timer_disarm(&Send_temp_timer_t);
回调函数的初始化也就是用它来做什么东西,第一个形参同上,第二个形参就是我们要处理的函数,最后一个形参写NULL,也就是0
os_timer_setfn(&Send_temp_timer_t, Send_temp, NULL); //a demo to process the data in uart rx buffer
os_timer_arm(&Send_temp_timer_t, 1000, 1);
第三行第一个形参同上,1000是定时器的周期,它的单位是毫秒,也就是1秒。我们可以在此更改他的定时周期。最后一个1代表一直循环进行。如果我们只想定时一次的话,就填0.
extern "C" {
#include "user_interface.h"
}
os_timer_t myTimer;//定義一個 Timer
bool tickOccured;
const int led_Timer = 5;
int Led_stat=HIGH;
void setup() {
pinMode(led_Timer, OUTPUT);//測試燈
digitalWrite(led_Timer, HIGH);
delay(3000);
Serial.begin(115200);
// put your setup code here, to run once:
Timer_init();
}
void loop() {
// put your main code here, to run repeatedly:
}
void Timer_init(void) {
os_timer_setfn(&myTimer, (os_timer_func_t *)timerLed, NULL);
os_timer_arm(&myTimer, 2000, true);
}
void timerLed(void *arg) {
Serial.println("Timer Call");
if(Led_stat==HIGH)
{
Led_stat=LOW;
}
else
{
Led_stat=HIGH;
}
digitalWrite(led_Timer, Led_stat);
// End of timerCallback
}
停止定时器
os_timer_disarm(&Send_temp_timer_t);
回调函数的初始化也就是用它来做什么东西,第一个形参同上,第二个形参就是我们要处理的函数,最后一个形参写NULL,也就是0
os_timer_setfn(&Send_temp_timer_t, Send_temp, NULL); //a demo to process the data in uart rx buffer
os_timer_arm(&Send_temp_timer_t, 1000, 1);
第三行第一个形参同上,1000是定时器的周期,它的单位是毫秒,也就是1秒。我们可以在此更改他的定时周期。最后一个1代表一直循环进行。如果我们只想定时一次的话,就填0.
extern "C" {
#include "user_interface.h"
}
os_timer_t myTimer;//定義一個 Timer
bool tickOccured;
const int led_Timer = 5;
int Led_stat=HIGH;
void setup() {
pinMode(led_Timer, OUTPUT);//測試燈
digitalWrite(led_Timer, HIGH);
delay(3000);
Serial.begin(115200);
// put your setup code here, to run once:
Timer_init();
}
void loop() {
// put your main code here, to run repeatedly:
}
void Timer_init(void) {
os_timer_setfn(&myTimer, (os_timer_func_t *)timerLed, NULL);
os_timer_arm(&myTimer, 2000, true);
}
void timerLed(void *arg) {
Serial.println("Timer Call");
if(Led_stat==HIGH)
{
Led_stat=LOW;
}
else
{
Led_stat=HIGH;
}
digitalWrite(led_Timer, Led_stat);
// End of timerCallback
}
多謝分享~~
回覆刪除