Hello @wa-berlin
you can't. Functions w/o numTimer argument will return the internal number assigned to a specific timer. You don't have direct control about which timer gets which number, but you can keep a record of the number assigned to a given timer to further manipulate it.
Below is an example with 2 timers (A and B). Timer A counts up ever 2 seconds, whereas timer B counts up every second and stops at 10.
With button A you can enable and disable timer A.
With button B you can restart timer B once it has stopped.
#include <M5Core2.h>
#include <utility/M5Timer.h>
M5Timer M5T;
int mytimerA = -1;
int mytimerB = -1;
int mycountA = 0;
int mycountB = 0;
void myTimerACB(void)
{
mycountA++;
}
void myTimerBCB(void)
{
mycountB++;
}
void setup()
{
M5.begin();
M5.Lcd.setTextSize(3);
mytimerA = M5T.setInterval(2000, myTimerACB);
mytimerB = M5T.setTimer(1000, myTimerBCB, 10);
}
void loop()
{
M5.update();
M5T.run();
if(M5.BtnA.wasPressed() == true)
{
if(M5T.isEnabled(mytimerA) == true)
{
M5T.disable(mytimerA);
}
else
{
M5T.enable(mytimerA);
}
}
if(M5.BtnB.wasPressed() == true)
{
if(M5T.isEnabled(mytimerB) == false)
{
M5T.deleteTimer(mytimerB);
mycountB = 0;
mytimerB = M5T.setTimer(1000, myTimerBCB, 10);
}
}
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("Timer A: %s\n", M5T.isEnabled(mytimerA) ? "enabled " : "disabled");
M5.Lcd.printf("Timer A: %04d", mycountA);
M5.Lcd.setCursor(0, 100);
M5.Lcd.printf("Timer B: %s\n", M5T.isEnabled(mytimerB) ? "enabled " : "disabled");
M5.Lcd.printf("Timer B: %04d", mycountB);
}
Good luck!
Felix