sensor.getAccel() 戻り値: x, y, z
加速度センサのX,Y,Z方向の成分を取得します。ただし、X方向は短辺方向です。Y方向は長辺方向です。setdevAccel(1)をセットしないと取得できません。
戻り値
- x: X方向(画面短辺方向)の加速度成分
- y: Y方向(画面長辺方向)の加速度成分
- z: Z方向の加速度成分
使用例
while(true)do --加速度を取得 ax, ay, az = sensor.getAccel() axo = axo*omomi + ax*(1-omomi) ayo = ayo*omomi + ay*(1-omomi) kaku = math.atan2( -ayo, axo ) angle = math.floor(kaku/pi*180) x = math.sin(kaku) y = math.cos(kaku) canvas.putg( 0, 0, w, h, 80, 0, wb, hb ) canvas.putrotg( cx, cy, angle, 0, 0, 79, 93 ) canvas.drawTextRotate("θ="..angle, cx-70*x, cy+70*y, angle, 24, color(255,0,0)) --画面タッチで終了 x,y,s = touch() if( s~=1 )then if( x>=cx-79/2 and x<=cx+79/2 and y>=cy-93/2 and y<=cy+93/2 )then break end end end