hinge¶
The hinge table allows you to get the hinge angle on foldable devices. You can read the current angle, or define the function hingeChanged to receive changes when the device folds.
The angle is nil when no reading is available or the device is not supported. Make sure you check for nil before using it in calculations, for example: local angle = hinge.angle or 0.
- angle: number | nil [readonly]¶
The hinge angle, in degrees. The value may be
nilif no hinge angle is available yet or the device is not supported.- Syntax:
local angle = hinge.angle if angle ~= nil then local radians = math.rad(angle) end
- hingeChanged(current, previous)¶
Use this global function to receive changes to the hinge angle. Codea calls it before drawing with the new and previous angles in degrees.
previousisnilfor the first reading and when readings resume after being unavailable.currentisnilwhen hinge input becomes unavailable. The function is not called while both values arenil.In draw-on-request mode, a hinge change causes Codea to draw a frame and call this function.
- Parameters:
current (
number | nil) – The new angle in degrees, ornilwhen unavailable.previous (
number | nil) – The previous angle in degrees, ornilif none was available.
- Syntax:
function hingeChanged(current, previous) if current == nil then print("Hinge input unavailable") elseif previous == nil then print("Hinge angle:", current) else print("Hinge angle change:", current - previous) end end