This shows you the differences between two versions of the page.
built_in:nxt_connect [2015/03/23 08:08] madlyr created |
built_in:nxt_connect [2015/03/23 16:10] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Connect ====== | ||
- | The **Connect** method connects to the Bluetooth device with given **name**. | ||
- | < | ||
- | |||
- | |||
- | ==== Example - ato connect on application start to NXT brick ==== | ||
- | Code by Dave Smart from AndroidScript forum. | ||
- | <code javascript> | ||
- | //Called when application is started. | ||
- | function OnStart() | ||
- | { | ||
- | //Create our screen layout. | ||
- | // | ||
- | |||
- | //Create NXT controller object. | ||
- | nxt = app.CreateNxt(); | ||
- | |||
- | //Connect to NXT by name. | ||
- | var deviceName = " | ||
- | var paired = nxt.IsPaired( deviceName ); | ||
- | if (paired) | ||
- | { | ||
- | app.ShowProgress( " | ||
- | nxt.SetOnConnect( nxt_OnConnect ); | ||
- | nxt.Connect( deviceName ); | ||
- | } | ||
- | } | ||
- | |||
- | //Handle successful brick connection. | ||
- | function nxt_OnConnect( success, nxt ) | ||
- | { | ||
- | if( success ) nxt.Beep( 2000, 200 ); | ||
- | else app.Alert( " | ||
- | app.HideProgress(); | ||
- | } | ||
- | |||
- | </ |