Difference between revisions of "Accelerometer"
From GiderosMobile
m |
m |
||
Line 7: | Line 7: | ||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
− | + | The [[Special:MyLanguage/Accelerometer|Accelerometer]] class is used to access accelerometer data. | |
− | === <translate> | + | === <translate>Example</translate> === |
− | |||
<source lang="lua"> | <source lang="lua"> | ||
local filter = 0.03 | local filter = 0.03 | ||
Line 34: | Line 33: | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | |||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
[[Special:MyLanguage/Accelerometer.isAvailable|Accelerometer.isAvailable]] ''<translate>is the accelerometer available?</translate>''<br> | [[Special:MyLanguage/Accelerometer.isAvailable|Accelerometer.isAvailable]] ''<translate>is the accelerometer available?</translate>''<br> | ||
Line 48: | Line 46: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | |||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
− | |||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
Revision as of 04:01, 4 January 2020
Supported platforms:
Available since: Gideros 2012.8
Inherits from: Object
Description
The Accelerometer class is used to access accelerometer data.
Example
local filter = 0.03
local fx, fy, fz = 0, 0, 0
--create instance
local accelerometer = Accelerometer.new()
--start receiving data
accelerometer:start()
function onEnterFrame(event)
---get values for example on each enter frame event
local x, y, z = accelerometer:getAcceleration()
fx = x * filter + fx * (1 - filter)
fy = y * filter + fy * (1 - filter)
fz = z * filter + fz * (1 - filter)
print("Y: "..math.floor(fy*90*-1))
print("X: "..math.floor(fx*90*-1))
print("Z: "..math.floor(fz*90*-1))
end
stage:addEventListener("enterFrame",onEnterFrame,self)
MethodsAccelerometer.isAvailable is the accelerometer available? |
EventsConstants |