<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Topics tagged with m5timer]]></title><description><![CDATA[A list of topics that have been tagged with m5timer]]></description><link>https://community.m5stack.com/tags/m5timer</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 20:27:18 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/tags/m5timer.rss" rel="self" type="application/rss+xml"/><pubDate>Invalid Date</pubDate><ttl>60</ttl><item><title><![CDATA[[Core2] M5Timer-Lib &#x2F;&#x2F; How to use &quot;numTimer&quot; in e.g. &quot;setInterval()&quot;]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/6797">@wa-berlin</a></p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">With button A you can enable and disable timer A.<br />
With button B you can restart timer B once it has stopped.</p>
#include &lt;M5Core2.h&gt;
#include &lt;utility/M5Timer.h&gt;

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);
}

<p dir="auto">Good luck!<br />
Felix</p>
]]></description><link>https://community.m5stack.com/topic/2918/core2-m5timer-lib-how-to-use-numtimer-in-e-g-setinterval</link><guid isPermaLink="true">https://community.m5stack.com/topic/2918/core2-m5timer-lib-how-to-use-numtimer-in-e-g-setinterval</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>