User Tools

Site Tools


plugins:bbc_microbit

Differences

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

Link to this comparison view

Next revision
Previous revision
plugins:bbc_microbit [2016/10/23 14:44]
madlyr created
plugins:bbc_microbit [2019/03/04 16:22] (current)
Line 12: Line 12:
  
 In order to use the micro:bit, you must first load the plugin at the top of your script using the **LoadPlugin** method like this: In order to use the micro:bit, you must first load the plugin at the top of your script using the **LoadPlugin** method like this:
-<code>app.LoadPlugin( "MicroBit" );</code>+<code javascript>app.LoadPlugin( "MicroBit" );</code>
 Then you can create the microbit object like this: Then you can create the microbit object like this:
-<code>microbit = app.CreateMicroBit();</code>+<code javascript>microbit = app.CreateMicroBit();</code>
 You will need to connect to your micro:bit using Bluetooth and you can scan for it like this: You will need to connect to your micro:bit using Bluetooth and you can scan for it like this:
-<code>microbit = microbit.Scan();</code>+<code javascript>microbit = microbit.Scan();</code> 
 + 
 +===== MicroBit Methods ===== 
 +^ Method                                                                             ^ Description                                                               ^ 
 +| [[microbit_analogread|AnalogRead( pin )]]                                          |                                                                           | 
 +| [[microbit_connect|Connect( address )]]                                            |                                                                           | 
 +| [[microbit_createcontroller|CreateController( size )]]                                                                                                       | 
 +| [[microbit_disconnect|Disconnect()]]                                               | Disconnects the Bluetooth link between your phone and the BBC micro:bit. 
 +| [[microbit_getimage|GetImage()]]                                                   | Returns full path to micro:bit top view image.                            | 
 +| [[microbit_getversion|GetVersion( num, txt )]]                                                                                                               | 
 +| [[microbit_oncancel|OnCancel()]]                                                                                                                             | 
 +| [[microbit_onconnect|OnConnect()]]                                                                                                                           | 
 +| [[microbit_ondevice|OnDevice( name, address, bonded, rssi )]]                      |                                                                           | 
 +| [[microbit_ondisconnect|OnDisconnect()]]                                                                                                                     | 
 +| [[microbit_onreceive|OnReceive( data )]]                                                                                                                     | 
 +| [[microbit_onselect|OnSelect( title, body )]]                                      |                                                                           | 
 +| [[microbit_reset|Reset()]]                                                                                                                                   | 
 +| [[microbit_save|Save()]]                                                                                                                                     | 
 +| [[microbit_scan|Scan( address )]]                                                  |                                                                           | 
 +| [[microbit_scrolltext|ScrollText( text, interval )]]                                                                                                         | 
 +| [[microbit_send|Send( msg )]]                                                      |                                                                           | 
 +| [[microbit_sendcode|SendCode( code )]]                                                                                                                       | 
 +| [[microbit_setleds|SetLEDs( bits )]]                                                                                                                         | 
 +| [[microbit_setonbutton|SetOnButton( callback )]]                                                                                                             | 
 +| [[microbit_setonconnect|SetOnConnect( callback )]]                                                                                                           | 
 +| [[microbit_setondevice|SetOnDevice( callback )]]                                                                                                             | 
 +| [[microbit_setondisconnect|SetOnDisconnect( callback )]]                                                                                                     | 
 +| [[microbit_setonevent|SetOnEvent( callback )]]                                                                                                               | 
 +| [[microbit_setonmotion|SetOnMotion( callback )]]                                                                                                             | 
 +| [[microbit_setonreceive|SetOnReceive( callback )]]                                                                                                           | 
 +| [[microbit_setontemp|SetOnTemp( callback )]]                                                                                                                 | 
 +| [[microbit_setsplitmode|SetSplitMode( mode, p1, p2 )]]                                                                                                       | 
 +| [[microbit_startscan|StartScan()]]                                                                                                                           | 
 +| [[microbit_stopscan|StopScan()]]                                                                                                                             | 
 +| [[microbit_watchaccelerometer|WatchAccelerometer( precision, interval, cancel )]]  |                                                                           | 
 +| [[microbit_watchbutton|WatchButton( name, cancel )]]                                                                                                         | 
 +| [[microbit_watchinput|WatchInput( pin, cancel )]]                                  |                                                                           | 
 + 
 + 
 +===== Using MicroBitCtrl Control ===== 
 + 
 +This control shows micro:bit image which shows interactive LED array and Bluetooth indicator. 
 + 
 +In order to use the MicroBitCtrl control, you must first load the plugin and initialize MicroBit object: 
 + 
 +<code javascript> 
 +//Load the MicroBit plugin. 
 +app.LoadPlugin( "MicroBit" ); 
 + 
 +//Called when application is started. 
 +function OnStart() 
 +
 +  //Lock screen orientation to Portrait. 
 +  app.SetOrientation( "Portrait" ); 
 + 
 +  //Create our main layout. 
 +  lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); 
 +  lay.SetBackColor( "#222222" ); 
 + 
 +  //Create the Microbit plugin. 
 +  microbit = app.CreateMicroBit(); 
 + 
 +  //Create MicroBit controller. 
 +  ctrl = microbit.CreateController( 0.9 ); 
 +  lay.AddChild( ctrl ); 
 + 
 +  //Create horizontal layout for buttons 
 +  layButs = app.CreateLayout( "Linear", "Horizontal" ); 
 +  layButs.SetMargins( 0,0.05,0,0 ); 
 +  lay.AddChild( layButs ); 
 + 
 +  //Create a bluetooth connect button. 
 +  btnConnect = app.CreateButton( "[fa-bluetooth-b]", 0.25, 0.15, "FontAwesome" ); 
 +  btnConnect.SetTextSize( 66 ); 
 +  btnConnect.SetTextColor( "#3366ff" ); 
 +  btnConnect.SetOnTouch( txtBT_OnTouchDown ); 
 +  layButs.AddChild( btnConnect ); 
 + 
 +  //Create clear button. 
 +  btnClear= app.CreateButton( "[fa-times]", 0.25, 0.15, "FontAwesome" ); 
 +  btnClear.SetTextSize( 66 ); 
 +  btnClear.SetTextColor( "#ff4444" ); 
 +  btnClear.SetOnTouch( btnClear_OnClick ); 
 +  layButs.AddChild( btnClear ); 
 + 
 +  //Add main layout to the app. 
 +  app.AddLayout( lay ); 
 +
 + 
 +//Handle Bluetooth button press. 
 +function txtBT_OnTouchDown() 
 +
 +  microbit.Scan(); 
 +
 + 
 +//Handle 'clear' button press. 
 +function btnClear_OnClick() 
 +
 +  ctrl.Clear(); 
 +
 +</code> 
 + 
 +===== MicroBitCtrl Methods ===== 
 +| [[microbitctrl_clear|Clear()]] | Clears LEDs to gray color. | 
 +| [[microbitctrl_sendledstates|SendLEDStates()]] | Sends new LED states to micro:bit. | 
 +| [[microbitctrl_setbluetoothstate|SetBluetoothState( connected )]] | If connected is true, then function sets Bluetooth indicator in blue color, if false, in gray color. | 
 +| [[microbitctrl_setled|SetLED( x, y )]] | Sets LED in x and y position (range 0..4). It sets LED in red color. | 
 +| [[microbitctrl_toggleled|ToggleLED( x, y )]] | Toggles LED in x and y position (range 0..4). It sets LED in red or gray color. | 
 +| [[microbitctrl_imgtouch_ontouch|imgTouch_OnTouch( ev )]] | Custom LED array touch handler. | 
  
 =====Examples===== =====Examples=====
  
-====Example - Send smiley face click to collapse contents ====+====Send smiley face click to collapse contents ====
 <code javascript> <code javascript>
 app.LoadPlugin( "MicroBit" ); app.LoadPlugin( "MicroBit" );
Line 43: Line 152:
  
    
-====Example - Send scrolling texts====+====Send scrolling texts====
 <code javascript> <code javascript>
 app.LoadPlugin( "MicroBit" ); app.LoadPlugin( "MicroBit" );
Line 71: Line 180:
  
  
-====Example - Detect button presses click to collapse contents====+====Detect button presses click to collapse contents====
 <code javascript> <code javascript>
 app.LoadPlugin( "MicroBit" ); app.LoadPlugin( "MicroBit" );
Line 99: Line 208:
  
  
-====Example - Detect movement click to collapse contents====+====Detect movement click to collapse contents====
 <code javascript> <code javascript>
 app.LoadPlugin( "MicroBit" ); app.LoadPlugin( "MicroBit" );
Line 133: Line 242:
 bit bit
  
-====Example - Save code on the micro:bit click to collapse contents====+====Save code on the micro:bit click to collapse contents====
 <code javascript> <code javascript>
 app.LoadPlugin( "MicroBit" ); app.LoadPlugin( "MicroBit" );
Line 183: Line 292:
 } }
 </code> </code>
 +
 +===== Troubleshooting =====
 +There is a separate article on [[microbit:troubleshooting|Troubleshooting]] this plugin.
 +
plugins/bbc_microbit.1477233852.txt.gz · Last modified: 2016/10/23 22:44 (external edit)