Skip to content

Commit a530827

Browse files
committed
Improve FPS limit
1 parent 595759b commit a530827

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples/Wasm_PyBadge_Dino/Wasm_PyBadge_Dino.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* export PATH=/opt/wasp/build/src/tools:$PATH
1818
* wasp wat2wasm --enable-numeric-values -o dino.wasm dino.wat
1919
* xxd -iC dino.wasm > dino.wasm.h
20+
*
21+
* Note: In Arduino IDE, select Tools->Optimize->Faster (-O3)
2022
*/
2123
#include "dino.wasm.h"
2224

@@ -183,12 +185,15 @@ void setup()
183185
// Output to display
184186
arcada.display->drawRGBBitmap(0, 40, (uint16_t*)(mem+0x5000), 160, 75);
185187

186-
//Serial.print("FPS: "); Serial.println(1000/(millis() - framestart));
188+
const uint32_t frametime = millis() - framestart;
189+
Serial.print("FPS: "); Serial.println(1000/frametime);
187190

188-
// Limit to 40..70 fps, depending on CPU/overclock setting (120..200MHz)
189-
//const int target_fps = map(F_CPU/1000000, 120, 200, 40, 70);
190-
const int target_fps = 40;
191-
while (millis() - framestart < (1000/target_fps)) { delay(1); }
191+
// Limit to 50..70 fps, depending on CPU/overclock setting (120..200MHz)
192+
//const int target_frametime = 1000/map(F_CPU/1000000, 120, 200, 50, 70);
193+
const uint32_t target_frametime = 1000/50;
194+
if (target_frametime > frametime) {
195+
delay(target_frametime - frametime);
196+
}
192197
}
193198

194199
if (result != m3Err_none) {

0 commit comments

Comments
 (0)