Timing the main loop in c on Teensy++ 2.0

Status
Not open for further replies.

Leonardo1123

New member
Hey there! I’m working on a program that allows the user to choose from multiple scripts and the simulates Nintendo Switch controller commands to be able to grind in a video game.

Because you’re able to choose from multiple scripts, and they can be very long, I’d like for the teensy to be able to report back how long it took to execute the main loop while still connected to my computer so I can hardcore that disclaimer into my code. (I tried timing a script of a known length and extrapolating the time vs duration, but hit some snags)

All the code I found for timing and delays were for teensyduino, and I’m working with code that does not use the arduino library, just straight c code. Am I still able to use this feature?
 
Do you have access to the number of milliseconds since startup? If so, I do this kind of thing:

TimeIt = millis(); // millis function returns number of ms since device start or reset
while (Ethernet.begin(mac) == 0) // 1 = success
{
if(millis() - TimeIt > 2000) // if a couple of seconds pass, try something else
{
Serial.println("Failed to configure Ethernet using DHCP");
getFixedIpAddress();
break;
}
}

Hope that helps,
Len
 
Do you have access to the number of milliseconds since startup?


I don't think so, I get the following error when trying to implement that:

Code:
Joystick.c:14:15: warning: implicit declaration of function 'millis' [-Wimplicit-function-declaration]
   14 |  int timeit = millis();

The other problem is that since my code is meant to interface with the switch, I'm not sure that it's totally ready to provide any information to my computer at the moment...

Also, is your code in c++? Unfortunately I forked a repo that relied heavily on C, so I'm kind of stuck with a bare-bones approach.
 
I was really just providing an approach. millis() may not be available in your library, but check around for something similar. At the very least, you may find a register for the chip you are programming that contains something similar. Yes, it is a variant of C++, but the concept should still work.

Len
 
Status
Not open for further replies.
Back
Top