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
Methods
ReadButtonAState
– Read the current state of the micro:bit’s A button. After a successful read, theButtonAStateReceived
event will be run.
ReadButtonBState
– Read the current state of the micro:bit’s B button. After a successful read, theButtonBStateReceived
event will be run.
RequestButtonAStateUpdates
– Request updates to the state of the micro:bit’s A button. After requesting updates, theButtonAStateReceived
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.
RequestButtonBStateUpdates
– Request updates to the state of the micro:bit’s B button. After requesting updates, theButtonBStateReceived
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.
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 inButtonAStateReceived
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 inButtonBStateReceived
.
Events
ButtonAStateReceived
– After performing a read or request for updates, theButtonAStateReceived
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.
ButtonBStateReceived
– After performing a read or request for updates, theButtonBStateReceived
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.