class FPS { int frames = 0; long startTime = 0; int fps = 0; FPS() { } void frame() { if (startTime==0) startTime = millis(); frames++; long t = millis() - startTime; if (t>1000) { fps = (int)(1000*frames/t); startTime += t; frames = 0; } } }