Hello,
I was playing with some code for the accelerometer and have it displaying just the gravityY value because I want to see how far the device is being tilted in that position. I have it working with the code below but it seems to have the starting point with the phone laying flat. If I hold the device vertical and tilt it forward the value goes from -1 towards 0. If I tilt it backwards it does the same. Is there any way to find out which direction it is tilting? If it is flat and I tilt it each direction it goes positive in one way and negative in another way. Is there any way of making the vertical position the starting position?
Thanks,
Warren
My code: (parts taken from Corona’s demo)
-- Text parameters local x = 40 local y = 40 local fontSize = 24 display.setDefault( "anchorX", 0.0 ) -- default to TopLeft anchor point for new objects display.setDefault( "anchorY", 0.0 ) local yg = display.newText( "0.0", x, y, native.systemFont, fontSize ) local function onAccelerate( event ) yg.text = event.yGravity \* 10 end -- Set up the accelerometer to provide measurements 60 times per second. -- Note that this matches the frame rate set in the "config.lua" file. system.setAccelerometerInterval( 60 ) -- Add runtime listeners -- Runtime:addEventListener ("accelerometer", onAccelerate);