This shows you the differences between two versions of the page.
built_in:nxt_isconnected [2015/03/10 20:59] madlyr created IsConnected |
built_in:nxt_isconnected [2015/03/11 18:03] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== IsConnected ====== | ||
- | The **IsConnected** function returns true if the NXT brick is currently connected to the phone/ | ||
- | < | ||
- | |||
- | ====Example - IsConnected Connect / Disconnect to NXT with FontAwesome icons==== | ||
- | <file javascript NxtConnect.js> | ||
- | var nxt, lay; | ||
- | function OnStart() | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | //Create Connect button. | ||
- | btnConnect = app.CreateButton( " | ||
- | btnConnect.SetMargins( 0.1, 0.01, 0.1, 0.01 ); | ||
- | btnConnect.SetTextSize( 24 ); | ||
- | btnConnect.SetOnTouch( btnConnect_OnTouch ); | ||
- | lay.AddChild( btnConnect ); | ||
- | |||
- | app.AddLayout( lay ); | ||
- | |||
- | nxt = app.CreateNxt(); | ||
- | nxt.SetOnConnected(onNXTConnected); | ||
- | } | ||
- | |||
- | function onNXTConnected() | ||
- | { | ||
- | if (nxt.IsConnected()) { | ||
- | btnConnect.SetText(" | ||
- | app.ShowPopup( " | ||
- | } | ||
- | } | ||
- | |||
- | function btnConnect_OnTouch() | ||
- | { | ||
- | if (nxt.IsConnected()) { | ||
- | app.ShowPopup( " | ||
- | nxt.Disconnect(); | ||
- | btnConnect.SetText(" | ||
- | } else { | ||
- | //Show list of NXT devices. | ||
- | nxt.ShowDevices(); | ||
- | } | ||
- | } | ||
- | </ |