Microbit 按钮

« 返回首页

Microbit 按钮

The Microbit_Button extension provides App Inventor with information about the state of the BBC micro:bit’s buttons. Developers can use this extension to request updates for when a user presses a button or read the current state of the buttons. The buttons have three states:

  • 0 - up
  • 1 - down
  • 2 - long pressed

More links:<ul><li>Download a sample projects for the micro:bit onboard buttons.</li><li>View the how to instructions for the micro:bit onboard buttons</li></ul>

Properties

  • BluetoothDevice – The BluetoothLE component connected to the micro:bit device (setter).

get Microbit_Button1 BluetoothDevice

set Microbit_Button1 BluetoothDevice  to

Methods

  • ReadButtonAState – Read the current state of the micro:bit’s A button. After a successful read, the ButtonAStateReceived event will be run.

call Microbit_Button1 ReadButtonAState

  • ReadButtonBState – Read the current state of the micro:bit’s B button. After a successful read, the ButtonBStateReceived event will be run.

call Microbit_Button1 ReadButtonBState

  • RequestButtonAStateUpdates – Request updates to the state of the micro:bit’s A button. After requesting updates, the ButtonAStateReceived will be run whenever the micro:bit reports a button state change to the app. Pressing and holding the button will result in a second event with the value 2 to indicate a long press.

call Microbit_Button1 RequestButtonAStateUpdates

  • RequestButtonBStateUpdates – Request updates to the state of the micro:bit’s B button. After requesting updates, the ButtonBStateReceived will be run whenever the micro:bit reports a button state change to the app. Pressing and holding the button will result in a second event with the value 2 to indicate a long press.

call Microbit_Button1 RequestButtonBStateUpdates

  • StopButtonAStateUpdates – Stop receiving updates about the state of the micro:bit’s A button. Note that there may be pending updates that have not been processed that will result in ButtonAStateReceived

call Microbit_Button1 StopButtonAStateUpdates

  • StopButtonBStateUpdates – Stop receiving updates about the state of the micro:bit’s B button. Note that there may be pending updates that have not been processed that will result in ButtonBStateReceived.

call Microbit_Button1 StopButtonBStateUpdates

Events

  • ButtonAStateReceived – After performing a read or request for updates, the ButtonAStateReceived event will be run with information about the button state.

Parameters:

  • Button_State_Value (number) — The state of the micro:bit’s A button; 0 for released, 1 for pressed, 2 for long-pressed.

when Microbit_Button1 ButtonAStateReceived Button_State_Value do

  • ButtonBStateReceived – After performing a read or request for updates, the ButtonBStateReceived event will be run with information about the button state.

Parameters:

  • Button_State_Value (number) — The state of the micro:bit’s B button; 0 for released, 1 for pressed, 2 for long-pressed.

when Microbit_Button1 ButtonBStateReceived Button_State_Value do