こちらのページを参考にしました。
RepeatTimer
時間設定の単位は、microseconds です。
5 秒は 5000000 になります。
プログラム
timer/timer.ino
// ---------------------------------------------------------------
/*
timer.ino
Sep/02/2021
*/
// ---------------------------------------------------------------
#include <M5Core2.h>
hw_timer_t *timer1 = NULL;
// ---------------------------------------------------------------
void IRAM_ATTR onTimer_proc()
{
int iix = millis() / 100;
Serial.println("*** onTimer_proc *** " + String(iix));
}
// ---------------------------------------------------------------
void setup()
{
M5.begin();
timer1 = timerBegin(0, 80, true);
timerAttachInterrupt(timer1, &onTimer_proc, true);
timerAlarmWrite(timer1, 5000000, true);
timerAlarmEnable(timer1);
Serial.println("*** setup *** aaa ***");
delay(1000);
Serial.println("*** setup *** bbb ***");
delay(1000);
Serial.println("*** setup *** ccc ***");
delay(1000);
}
// ---------------------------------------------------------------
void loop()
{
float ffx = millis()/ 1000.0;
Serial.println("\t*** loop *** aaa *** " + String(ffx));
delay(3000);
ffx = millis()/ 1000.0;
Serial.println("\t*** loop *** bbb ***" + String(ffx));
delay(3000);
ffx = millis()/ 1000.0;
Serial.println("\t*** loop *** ccc ***" + String(ffx));
delay(3000);
}
// ---------------------------------------------------------------
Arduino IDE
実行結果
$ cu -s 115200 -l /dev/ttyUSB0
Connected.
*** loop *** aaa *** 4.66
*** onTimer_proc *** 66
*** loop *** bbb ***7.66
*** loop *** ccc ***10.66
*** onTimer_proc *** 116
*** loop *** aaa *** 13.66
*** onTimer_proc *** 166
*** loop *** bbb ***16.66
*** loop *** ccc ***19.66
*** onTimer_proc *** 216
*** loop *** aaa *** 22.66
*** loop *** bbb ***25.66
*** onTimer_proc *** 266
*** loop *** ccc ***28.66
*** onTimer_proc *** 316
*** loop *** aaa *** 31.66
*** loop *** bbb ***34.66