Microbit Io Pin:板载引脚
The Microbit_Io_Pin
component lets users configure the BBC micro:bit’s analog pins for input and output, and to read, write, and request notifications for the I/O pin states.
More links:<ul><li>RGB LED control: sample project and tutorial.</li><li>Read knob status: sample project and tutorial.</li><li>Read switch status: sample project and tutorial.</li></ul>
Properties
Methods
ReadPinADConfiguration
– Read the state of the micro:bit’s pin configuration, specifically whether each pin is configured as digital (0 or 1) or analog (0 to 255). After a successful read, thePinADConfigurationReceived
event will be run.
ReadPinData
– Read a single sample of the pin states from the micro:bit. On successful read, thePinDataReceived
event will be run. Prior to reading the pins, one should configure the pins for input using theWritePinIOConfiguration
method.
ReadPinIOConfiguration
– Read the current input/output configuration of the micro:bit’s pins. After a successful read, thePinIOConfigurationReceived
event will be run.
RequestPinDataUpdates
– Request updates to any micro:bit pins configured as input pins. After requesting updates, thePinDataReceived
will be run whenever the micro:bit reports changes to its input pins.
StopPinDataUpdates
– Stop receiving updates about the state of the micro:bit’s I/O pins. Note that there may be pending updates that have not been processed that will result in additionalPinDataReceived
events.
WritePWMControl
– Writes the PWM control field on the micro:bit. The PWM control field is a variable length array of one or two instances of a data structure containing a 1-byte pin field (range 0-19), a 2-byte value field (range 0-1024), and a 4-byte period field (in milliseconds).
Parameters:
* <code>PWM\_Control\_Field</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
The PWM control field data as defined in the WritePWMControl method description.
WritePinADConfiguration
– TheWritePinADConfiguration
is used to configure whether pins on the micro:bit are analog or digital. ThePin\_AD\_Config\_Value
is composed of three bytes that represent 19 bits, one for each pin on the micro:bit. A 0 bit indicates a digital pin and a 1 bit indicates an analog pin. TheWrotePinADConfiguration
event will be run after successfully writing a new pin configuration.
Parameters:
* <code>Pin\_AD\_Config\_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of 8-bit values that are composed into a 19-bit mask, one bit per pin on the micro:bit.
WritePinData
– TheWritePinData
is used to set the output values of the micro:bit’s pins if configured as output pins using theWritePinIOConfiguration
method. After the pins are written, theWrotePinData
event will be run.
Parameters:
* <code>IO\_Pin\_Data</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) — A list of up to 19 values from 0-255 to be output to the micro:bit's pins.
WritePinIOConfiguration
– TheWritePinIOConfiguration
method is used to configure the micro:bit’s pins for input or output. ThePin\_IO\_Config\_Value
parameter should be a 3-element list where each element is a number from 0-255 composing a 19-bit bitmask. A 0-bit indicates an output and a 1-bit indicates an input.
Parameters:
* <code>Pin_IO_Config_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of 8-bit values that are composed into a 19-bit mask, one bit per pin on the micro:bit.
Events
PinADConfigurationReceived
– ThePinADConfigurationReceived
event is run after a successful call to theReadPinADConfiguration
method is returned by the micro:bit.
Parameters:
* <code>Pin\_AD\_Config\_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of analog/digital pin states configured on the micro:bit.
PinDataReceived
– ThePinDataReceived
event will be run after the micro:bit sends the status of its input pins. This will typically follow calls toReadPinData
orRequestPinData
.
Parameters:
* <code>IO_Pin_Data</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
The state of the micro:bit's input pins. Pins not configured for input will have 0 value.
PinIOConfigurationReceived
– ThePinIOConfigurationReceived
event will be run after the micro:bit’s pins’ input/output configuration is read.Pin\_IO\_Config\_Value
will be a list of three bytes valued from 0-255 composing a 19-bit mask indicating the input or output state of each of the 19 pins provided by the micro:bit. A 0 bit indicates output and a 1 bit indicates input.
Parameters:
* <code>Pin\_IO\_Config\_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of 8-bit values that are composed into a 19-bit mask, one bit per pin on the micro:bit.
WrotePWMControl
– TheWrotePWMControl
event is run after a successful write to the micro:bit’s pulse-width modulation control service. The value of the control field that was written will be passed as thePWM\_Control\_Field
.
Parameters:
* <code>PWM\_Control\_Field</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
The control information written to the micro:bit.
WrotePinADConfiguration
– TheWrotePinADConfiguration
event is run after a successful write to the micro:bit’s configuration server for analog and digital pins.Pin\_AD\_Config\_Value
will be the list of bytes that were written as part of the last call to the service.
Parameters:
* <code>Pin\_AD\_Config\_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of 8-bit values that are composed into a 19-bit mask, one bit per pin on the micro:bit.
WrotePinData
– TheWrotePinData
event will be run after the micro:bit’s output pins are successfully written by a call to theWritePinData
method.
Parameters:
* <code>IO\_Pin\_Data</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) — A list of up to 19 values from 0-255 that were written to the micro:bit's
pins from the last call to <a href="#WritePinData"><code>WritePinData</code></a>.
WrotePinIOConfiguration
– TheWrotePinIOConfiguration
event will run after a successful update of the micro:bit’s input/output pin configuration.Pin\_IO\_Config\_Value
that was sent to the device will be passed as a parameter to the event.
Parameters:
* <code>Pin\_IO\_Config\_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#emptylist">_list_</a>) —
A list of 8-bit values that are composed into a 19-bit mask, one bit per pin on the micro:bit.