[Core2] M5Timer-Lib // How to use "numTimer" in e.g. "setInterval()"
-
I want to use the M5Timer Library with Core2.
In <M5Timer.h> there are functions having a <numTimer> argument and those without.Questions:
How can I use

with a certain timer?
I am simply missing the argument "numTimer" in the function.A working example for Core2 would be helpful.
Thank you in advance. -
Hello @wa-berlin
you can't. Functions w/o
numTimerargument 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login