Returns a Sensor object.
app.CreateSensor(
type,
options ) ->
app object - Sensor
Example - Accelerometer
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
txt = app.CreateText( "", 0.8, 0.3, "Multiline" );
lay.AddChild( txt );
app.AddLayout( lay );
sns = app.CreateSensor( "Accelerometer" );
sns.SetOnChange( sns_OnChange );
sns.Start();
}
function sns_OnChange( x, y, z, time )
{
txt.SetText( "x="+x + "\n y="+y + "\n z="+z );
}
Example - Orientation
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
txt = app.CreateText( "", 0.8, 0.3, "Multiline" );
lay.AddChild( txt );
app.AddLayout( lay );
sns = app.CreateSensor( "Orientation" );
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 );
}
Example - Light
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
txt = app.CreateText( "", 0.8, 0.3 );
lay.AddChild( txt );
app.AddLayout( lay );
sns = app.CreateSensor( "Light" );
sns.SetOnChange( sns_OnChange );
sns.Start();
}
function sns_OnChange( lux )
{
txt.SetText( "level = " + lux + " lux" );
}
The following methods are avaiable on the Sensor object: