cpuLoad() how and best way to use

Hi Cool People,

Could someone share a code example of the best way to use cpuLoad()? And is it better to print the results to the serial monitor or to the Arduboy screen? I guess one would use less cpu?

Thank you.


I think printing to the screen would generally be better if you’re doing it once per frame.

Note that if you’re just trying to determine if your rendering time is within your chosen frame rate (CPU load is less than 100%), the nextFrameDEV() function is available for this (in place of nextFrame()). It will light the yellow TX LED if CPU load exceeds 100%.

1 Like

That is indeed cool, I saw you and others help people with that, thank you. I would like to give cpuLoad a try. Would you mind showing it’s use in code, I didn’t sleep last night and I can’t think my way through it right now.

Assuming the common game rendering method for the Arduboy:

#include <Arduboy2.h>

Arduboy2 arduboy;

void setup() {
  arduboy.setFrameRate(60); // 60 is default. Set as desired.

void loop() {
  if (!arduboy.nextFrame()) { // You can use nextFrameDEV() if you like.

  arduboy.pollButtons(); // needed if you use justPressed()

  // Your game code goes here, as usual.

  // You can set the cursor to any location where
  // you want the load to be displayed.
  // arduboy.clear() will set it to 0, 0 so you don't
  // need the following line if you want it there and
  // don't use text for anything else.
  arduboy.setCursor(0, 0);

1 Like

Dangit, yes of course. Jeez. Thanks Scott.