磁気センサの起動と終了を設定

構文 sensor.setdevMagnet(Pow)
説明 磁気センサの起動と終了を設定します。
引数 Pow: 0:終了, 1:起動
センサを起動させないと値が取得できません。
戻り値 なし

------------------------------------------
-- 磁気センサの起動と終了を設定するサンプル setdevMagnet_sample.lua
------------------------------------------
function main()
 
  local w,h = canvas.getviewSize()
  local xx, yy = 0, 50
 
  canvas.drawCls(color(255,255,255))
  canvas.drawText("磁気センサの起動と終了を設定するサンプル", 0, 0, 24, color(0,0,0))
  canvas.drawText("画面の右下の四角枠内のタッチで終了します。", 0, 30, 24, color( 0, 0, 0))
  canvas.drawRect( w-100, h-100, w-2, h-2, color( 0, 0, 0))
  sensor.setdevMagnet(1)
 
  while not ((xx >= w-100 and xx <= w-2) and (yy >= h-100 and yy <= h-2)) do
    xx, yy,mode = touch(0)
      x, y, z = sensor.getMagnet()
      canvas.drawText("X方向(画面短辺方向)の磁気成分 = " .. x .. "                ", 0, 80, 24, color(0,0,0), color(255,255,255))
      canvas.drawText("Y方向(画面長辺方向)の磁気成分 = " .. y .. "                ", 0, 110, 24, color(0,0,0), color(255,255,255))
      canvas.drawText("Z方向の磁気成分         = " .. z .. "                ", 0, 140, 24, color(0,0,0), color(255,255,255))
  end
 
  sensor.setdevMagnet(0)
 
end
 
main()
 

1.磁気センサの起動と終了を設定するサンプルです。右下の四角枠内タッチで終了します。


コメント(最大10行)
名前:
コメント

すべてのコメントを見る



タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2011年12月25日 10:15
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。