User Tools

Site Tools


built_in:nxt_connect

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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**.  
-<code>nxt.IsPaired( name );</code> 
- 
- 
-==== 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. 
- //CreateLayout(); 
- 
- //Create NXT controller object. 
- nxt = app.CreateNxt();    
-  
- //Connect to NXT by name. 
- var deviceName = "myNXTbrick"; 
- var paired = nxt.IsPaired( deviceName ); 
- if (paired) 
- { 
-     app.ShowProgress( "Connecting to "+deviceName+"..." ); 
-            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( "Failed to connect!" ); 
-    app.HideProgress(); 
-} 
- 
-</code> 
built_in/nxt_connect.txt ยท Last modified: 2015/03/23 16:10 (external edit)