This shows you the differences between two versions of the page.
built_in:sensors [2015/03/08 09:30] octazid completed |
built_in:sensors [2018/01/03 10:23] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Sensors ====== | ||
- | // | ||
- | |||
- | ===== Description ===== | ||
- | Create Sensor objects using the **CreateSensor** function of the [[built_in: | ||
- | < | ||
- | Types available are: | ||
- | * **" | ||
- | * **" | ||
- | * **" | ||
- | * **" | ||
- | * **" | ||
- | |||
- | You can use the **SetOnChange** function of the Sensor to set the name of a function you want to be called when a the changes occur. | ||
- | |||
- | Change the rate that a sensor checks for changes by adding one the options **" | ||
- | " | ||
- | |||
- | |||
- | ===== Methods ===== | ||
- | Some controls use the same methods.\\ | ||
- | For examples of the **[[same methods]]** look here. | ||
- | ^Method ^Description ^ | ||
- | |Sensor.Destroy() | | | ||
- | |Sensor.GetAzimuth() | | | ||
- | |Sensor.GetHeight() | | | ||
- | |Sensor.GetPitch() | | | ||
- | |Sensor.GetRoll() | | | ||
- | |Sensor.GetType() | | | ||
- | |Sensor.SetMinChange( value ) | a value between 0 and 1| | ||
- | |Sensor.SetOnChange( callback ) | | | ||
- | |Sensor.Start() | | | ||
- | |Sensor.Stop() | | | ||
- | |||
- | ===== Examples ===== | ||
- | ^Sensor Type ^Code Example ^ | ||
- | |Accelerometer | <code javascript> | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | txt = app.CreateText( "", | ||
- | lay.AddChild( txt ); | ||
- | app.AddLayout( lay ); | ||
- | |||
- | sns = app.CreateSensor( " | ||
- | sns.SetOnChange( sns_OnChange ); | ||
- | sns.Start(); | ||
- | |||
- | } | ||
- | |||
- | function sns_OnChange( x, y, z, time ) | ||
- | { | ||
- | txt.SetText( " | ||
- | </ | ||
- | |Orientation | <code javascript> | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | txt = app.CreateText( "", | ||
- | lay.AddChild( txt ); | ||
- | app.AddLayout( lay ); | ||
- | |||
- | sns = app.CreateSensor( " | ||
- | sns.SetOnChange( sns_OnChange ); | ||
- | sns.Start(); | ||
- | |||
- | } | ||
- | |||
- | function sns_OnChange( azimuth, pitch, roll, time ) | ||
- | { | ||
- | var msg = " azimuth = " + azimuth.toFixed(1); | ||
- | msg += "\n pitch = " + pitch.toFixed(1); | ||
- | msg += "\n roll = " + roll.toFixed(1); | ||
- | txt.SetText( msg ); | ||
- | } | ||
- | </ | ||
- | |Light | <code javascript> | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | txt = app.CreateText( "", | ||
- | lay.AddChild( txt ); | ||
- | app.AddLayout( lay ); | ||
- | |||
- | sns = app.CreateSensor( " | ||
- | sns.SetOnChange( sns_OnChange ); | ||
- | sns.Start(); | ||
- | |||
- | } | ||
- | |||
- | function sns_OnChange( lux ) | ||
- | { | ||
- | txt.SetText( "level = " + lux + " lux" ); | ||
- | } | ||
- | |||
- | </ |