Back

CreateSensor

Returns a Sensor object.

For more information in the detailed docs see CreateSensor

  sns = 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 );
}
    Copy     Copy All       Run      

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 );
}
    Copy     Copy All       Run      

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" );
}
    Copy     Copy All       Run      

The following methods are available on the Sensor object:

  GetAzimuth() → unknown
  GetNames() → unknown
  GetPitch() → unknown
  GetRoll() → unknown
  GetType() → string: "Sensor"
  GetValues() → unknown
  Method( name, types, p1, p2, p3, p4 )
  Start()
  Stop()

string: "Accelerometer" or "MagneticField" or "Orientation" or "Light" or "Proximity" or "Temperature" or "GameRotation" or "GeomagneticRotation" or "Gravity" or "Gyroscope" or "HeartRate" or "Acceleration" or "Pressure" or "Humidity" or "RotationMotion" or "StepCounter" or "StepDetector"
unknown
Returns the control class name.
string
string: comma separated: "boolean", "char", "byte", "short", "int", "long", "float", "double"
Allows access to other functions defined on the object in Java via reflection.
function()