NOBのArduino日記!

NOBのArduino日記!

趣味は車・バイク・自転車・ラジコン・電子工作です。

Arduino IDE(gb.battery.show関数の使い方)

■gb.battery.show関数
 Gamebuimo.hライブラリのgb.battery.show関数は、画面の右上隅にバッテリレベルインジケータを表示するかどうかを選択します。
 gb.titleScreenが呼び出されるたびに、バッテリレベルインジケータがtrueに設定されます。

■使用例
 gb.battery.show関数を使ったArduinoIDEのプログラム例は図1の通りです。
 このプログラムを実行するとsetup関数中のgb.begin関数でGamebuinoオブジェクトを初期化し、initGame関数で画面に「PHYSICS DEMO」とセンタリングして表示し、gb.battery.show関数でバッテリーインジケーターを隠します。
 スタート画面でキーボードの「K」(GamebuinoのA)ボタンを押すと、gb.getCpuLoad関数によって取得されたCPU負荷率が画面左上に「CPU:**%」と、表示されます。
 この画面では矩形のキャラをカーソルキーで動かすことが可能になります。
 キャラを上下左右に移動しするとCPU負荷率が上がり、数値で確認する事が出来ます。
 参考に図1プログラムをHEXファイルに変換し、それをSimbuino4Webエミュレートした結果を図2に示します。

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

//define de Box structure for obstacles
typedef struct   {
   byte w;
   byte x;
   byte h;
   byte y;
} Box;

//define de MovingBox structure for player
typedef struct   {
   byte w;
   float x;
   float xv;
   byte h;
   float y;
   float yv;
} MovingBox;

void setup()
{
   gb.begin();
   initGame();
}

void loop() {
   if (gb.update()) {
       //pause the game if C is pressed
       if (gb.buttons.pressed(BTN_C)) {
           initGame();

       }

       updatePlayer();
       updateObstacles();

       drawObstacles();
       drawPlayer();
       gb.display.print(F("CPU:"));
       gb.display.print(gb.getCpuLoad());
       gb.display.print(F("%"));


   }
}

void initGame() {
   gb.titleScreen(F("       PHYSICS DEMO\n\nControls:\n \25 jump\n \26 crouch "));
   gb.pickRandomSeed();     //pick a different random seed each time for games to be different
   gb.battery.show   =   false;     //バッテリーインジケーターを隠す

   initObstacles();
   initPlayer();
}
イメージ 1
図1:プログラム例
 

 イメージ 1
図2:プログラム実行結果

 

■構文
 gb.battery.show = true or false

■パラメータ
 true:バッテリーインジケーターを表示する
 false:バッテリーインジケーターを表示しない

■戻り値
 ありません

 

イメージ 1 イメージ 3
励みになりますのでよければクリック下さい(^o^)/

↩【Gamebuinoリファレンス】目次に戻る