NOBのArduino日記!

NOBのArduino日記!

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

Arduino IDE(gb.display.println関数の使い方)

■gb.display.println関数
 Gamebuimo.hライブラリのgb.display.println関数は、画面にデータを描画し、キャリッジリターン文字(ASCII 13または '\ r')と改行文字(ASCII 10または '\ n')を続けます。このコマンドは、gb.display.print関数と同じ形式をとります。

■使用例
  gb.display.println関数を使ったArduinoIDEのプログラム例は図1の通りです。
 このプログラムを実行するとsetup関数中のgb.begin関数でGamebuinoオブジェクトを初期化し、gb.titleScreen関数で画面に「My first game」と表示します。
 スタート画面でキーボードの「K」(GamebuinoのA)ボタンを押すと画面下にgb.popup関数により「Let's go!」と表示され、同時にgb.display.println関数により画面左上に「Hello world!」と表示され、その下にgb.frameCount変数の値がリアルタイムに更新されます。
 参考に図1プログラムをHEXファイルに変換し、それをSimbuino4Webエミュレートした結果を図2に示します。

//imports the SPI library (needed to communicate with Gamebuino's screen)
#include <SPI.h>
//imports the Gamebuino library
#include <Gamebuino.h>
//creates a Gamebuino object named gb
Gamebuino gb;

// the setup routine runs once when Gamebuino starts up
void setup() {
  // initialize the Gamebuino object
  gb.begin();
  //display the main menu:
  gb.titleScreen(F("My first game"));
  gb.popup(F("Let's go!"), 100);
}

// the loop routine runs over and over again forever
void loop() {
  //updates the gamebuino (the display, the sound, the auto backlight... everything)
  //returns true when it's time to render a new frame (20 times/second)
  if (gb.update()) {
    //prints Hello World! on the screen
    gb.display.println(F("Hello World!"));
    //declare a variable named count of type integer :
    int count;
    //get the number of frames rendered and assign it to the "count" variable
    count = gb.frameCount;
    //prints the variable "count"
    gb.display.println(count);
  }
}
イメージ 1
図1:プログラム例
 

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

 

■構文
 gb.display.println(text or numbers)

■パラメータ
 text:任意の長さの任意の文字列。F( "テキスト")でもかまいません。
 numbers:任意の数字。

■戻り値
 戻り値:ありません。

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

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