Then you can add code to the sns_OnChange function to perform whatever actions you need to.
// code -------------------------
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
txt = app.CreateText( "Waiting", 0.8, 0.3, "multiLine,left" );
lay.AddChild( txt );
app.AddLayout( lay );
sns = app.CreateSensor( "Proximity");
sns.SetOnChange( sns_OnChange );
sns.Start();
}
function sns_OnChange( distance ,p2, p3,time)
{
txt.SetText( "Distance = " + distance +
"\ntime=" + time);
}