概要
ヒャッハー!約60fpsだぜ!
計測してみる
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #include <Arduboy.h> Arduboy boy; typedef signed char s8;typedef signed short s16;typedef signed int s32;typedef unsigned char u8;typedef unsigned short u16;typedef signed short fx16;s16 x = 0 ; s32 cnt = 0 ; unsigned long frameload = 0 ;unsigned long prev_count = 0 ;#define FX16_SHIFT (7) #define FX16_ONE (1<<FX16_SHIFT) #define FX16_CONST(v) ((s16)((v) * 128.0f)) #define FX16_TOINT(v) ((v)>>FX16_SHIFT) #define FX16_MUL(a, b) (((a)*(b))>>FX16_SHIFT) #define FX16_DIV(a, b) ((s16)(((s32)(a)<<FX16_SHIFT)/(b))) struct Object { fx16 x, y; }; Object obj; void update () { if (boy.pressed(LEFT_BUTTON)) { obj.x -= FX16_CONST(1.5f ); } if (boy.pressed(RIGHT_BUTTON)) { obj.x += FX16_CONST(1.5f ); } if (boy.pressed(UP_BUTTON)) { obj.y -= FX16_CONST(1.5f ); } if (boy.pressed(DOWN_BUTTON)) { obj.y += FX16_CONST(1.5f ); } boy.drawCircle(FX16_TOINT(obj.x), FX16_TOINT(obj.y), 8 , 0xff ); } void setup () { boy.begin (); boy.setFrameRate(60 ); } void loop () { if (!boy.nextFrame()) return ; auto now = micros (); frameload = now - prev_count; prev_count = now; boy.clear (); update(); boy.display (); if (++cnt > 60 ) { Serial .println (frameload); cnt = 0 ; } }
関係ないコードも混じってますが、とりあえず、毎フレーム micros()
で起動後から経過した時間を取得して、一秒に一回シリアルへ出力。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 [k-ya@meteor] ~/Documents/Arduino/build % picocom /dev/cu.usbmodem1411 picocom v2.1 port is : /dev/cu.usbmodem1411 flowcontrol : none baudrate is : 9600 parity is : none databits are : 8 stopbits are : 1 escape is : C-a local echo is : no noinit is : no noreset is : no nolock is : no send_cmd is : sz -vv receive_cmd is : rz -vv -E imap is : omap is : emap is : crcrlf,delbs, Type [C-a] [C-h] to see available commands Terminal ready 16384 16384 16384 16384 16384 15360 15360 15360 16384 16384 16384 16384 16384 15360 15368 Thanks for using picocom
タイマー精度の関係なのか、16384というこれはこれでキリのいい数字が出ているが、大体60fps出ているようだ。