Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pin parameters variable #5700

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/core/_locales/core-jsdoc-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
"pins.P7": "Pin P7",
"pins.P8": "Pin P8",
"pins.P9": "Pin P9",
"pins.analogPin": "Returns the value of a C++ runtime constant",
"pins.analogPitch": "Send a pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogPitchVolume": "Gets the volume the pitch pin from 0..255",
"pins.analogPitch|param|frequency": "frequency to modulate in Hz.",
Expand All @@ -633,6 +634,7 @@
"pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0",
"pins.createBuffer": "Create a new zero-initialized buffer.",
"pins.createBuffer|param|size": "number of bytes in the buffer",
"pins.digitalPin": "Returns the value of a C++ runtime constant",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalReadPin|param|name": "pin to read from, eg: DigitalPin.P0",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
Expand Down
2 changes: 2 additions & 0 deletions libs/core/_locales/core-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,15 @@
"music|block": "music",
"parseFloat|block": "parse to number %text",
"parseInt|block": "parse to integer %text",
"pins.analogPin|block": "analog pin %pin",
"pins.analogPitchVolume|block": "analog pitch volume",
"pins.analogPitch|block": "analog pitch %frequency|for (ms) %ms",
"pins.analogReadPin|block": "analog read|pin %name",
"pins.analogSetPeriod|block": "analog set period|pin %pin|to (µs)%micros",
"pins.analogSetPitchPin|block": "analog set pitch pin %name",
"pins.analogSetPitchVolume|block": "analog set pitch volume $volume",
"pins.analogWritePin|block": "analog write|pin %name|to %value",
"pins.digitalPin|block": "digital pin %pin",
"pins.digitalReadPin|block": "digital read|pin %name",
"pins.digitalWritePin|block": "digital write|pin %name|to %value",
"pins.i2cReadNumber|block": "i2c read number|at address %address|of format %format|repeated %repeat",
Expand Down
476 changes: 268 additions & 208 deletions libs/core/blocks-test/pins.blocks
100644 → 100755

Large diffs are not rendered by default.

82 changes: 69 additions & 13 deletions libs/core/blocks-test/test.blocks
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,51 @@
<field name="mode">DisplayMode.Greyscale</field>
<next>
<block type="device_set_analog_pin">
<field name="name">AnalogPin.P4</field>
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P4</field>
</block>
</value>
<value name="value">
<shadow type="math_number_minmax" id=",:%8N*FL3wa-zFQ[+^$9">
<mutation min="0" max="1023" label="Value" precision="0"></mutation>
<field name="SLIDER">1023</field>
</shadow>
<block type="device_get_analog_pin">
<field name="name">AnalogPin.P13</field>
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P13</field>
</block>
</value>
</block>
</value>
<next>
<block type="device_set_digital_pin">
<field name="name">DigitalPin.P10</field>
<value name="name">
<block type="digital_pin">
<field name="pin">DigitalPin.P10</field>
</block>
</value>
<value name="value">
<shadow type="math_number_minmax" id="W~pvdj%jFEj?EHmT{81Z">
<mutation min="0" max="1" label="Value" precision="0"></mutation>
<field name="SLIDER">0</field>
</shadow>
<block type="device_get_digital_pin">
<field name="name">DigitalPin.P15</field>
<value name="name">
<block type="digital_pin">
<field name="pin">DigitalPin.P15</field>
</block>
</value>
</block>
</value>
<next>
<block type="device_set_analog_period">
<value name="pin">
<block type="analog_pin">
<field name="pin">AnalogPin.P9</field>
</block>
</value>
<value name="micros">
<shadow type="math_number" id="[email protected]`n=p;34mQOpC">
<field name="NUM">1234</field>
Expand Down Expand Up @@ -218,7 +238,11 @@
</value>
<next>
<block type="device_set_servo_pin">
<field name="name">AnalogPin.P20</field>
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P20</field>
</block>
</value>
<value name="value">
<shadow type="math_number_minmax" id="xC9lYf`{!gA-A8R+#~L.">
<mutation min="0" max="180" label="Value" precision="0"></mutation>
Expand All @@ -230,7 +254,11 @@
</value>
<next>
<block type="device_set_servo_pulse">
<field name="value">AnalogPin.P14</field>
<value name="value">
<block type="analog_pin">
<field name="pin">AnalogPin.P14</field>
</block>
</value>
<value name="micros">
<shadow type="math_number" id="@*C3kzJkeeUQ@s$N5?K}">
<field name="NUM">1500</field>
Expand Down Expand Up @@ -510,7 +538,11 @@
</statement>
</block>
<block type="pins_on_pulsed" x="1538" y="929">
<field name="pin">DigitalPin.P10</field>
<value name="pin">
<block type="digital_pin">
<field name="pin">DigitalPin.P10</field>
</block>
</value>
<field name="pulse">PulseValue.Low</field>
<statement name="HANDLER">
<block type="i2c_writenumber">
Expand Down Expand Up @@ -544,7 +576,11 @@
</value>
<next>
<block type="device_set_pin_events">
<field name="pin">DigitalPin.P0</field>
<value name="pin">
<block type="digital_pin">
<field name="pin">DigitalPin.P0</field>
</block>
</value>
<field name="type">PinEventType.Touch</field>
<next>
<block type="spi_frequency">
Expand All @@ -555,10 +591,18 @@
</value>
<next>
<block type="device_analog_set_pitch_pin">
<field name="name">AnalogPin.P2</field>
<value name="name">
<block type="analog_pin">
<field name="pin">AnalogPin.P2</field>
</block>
</value>
<next>
<block type="device_set_pull">
<field name="pin">DigitalPin.P2</field>
<value name="pin">
<block type="digital_pin">
<field name="pin">DigitalPin.P2</field>
</block>
</value>
<field name="pull">PinPullMode.PullDown</field>
<next>
<block type="spi_format">
Expand All @@ -574,9 +618,21 @@
</value>
<next>
<block type="spi_pins">
<field name="mosi">DigitalPin.P9</field>
<field name="miso">DigitalPin.P14</field>
<field name="sck">DigitalPin.P16</field>
<value name="mosi">
<block type="digital_pin">
<field name="pin">DigitalPin.P9</field>
</block>
</value>
<value name="miso">
<block type="digital_pin">
<field name="pin">DigitalPin.P14</field>
</block>
</value>
<value name="sck">
<block type="digital_pin">
<field name="pin">DigitalPin.P16</field>
</block>
</value>
<next>
<block type="control_reset"></block>
</next>
Expand Down
38 changes: 38 additions & 0 deletions libs/core/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,62 +428,100 @@ declare namespace led {


declare const enum DigitalPin {
//% blockIdentity="pins.digitalPin"
P0 = 100, // MICROBIT_ID_IO_P0
//% blockIdentity="pins.digitalPin"
P1 = 101, // MICROBIT_ID_IO_P1
//% blockIdentity="pins.digitalPin"
P2 = 102, // MICROBIT_ID_IO_P2
//% blockIdentity="pins.digitalPin"
P3 = 103, // MICROBIT_ID_IO_P3
//% blockIdentity="pins.digitalPin"
P4 = 104, // MICROBIT_ID_IO_P4
//% blockIdentity="pins.digitalPin"
P5 = 105, // MICROBIT_ID_IO_P5
//% blockIdentity="pins.digitalPin"
P6 = 106, // MICROBIT_ID_IO_P6
//% blockIdentity="pins.digitalPin"
P7 = 107, // MICROBIT_ID_IO_P7
//% blockIdentity="pins.digitalPin"
P8 = 108, // MICROBIT_ID_IO_P8
//% blockIdentity="pins.digitalPin"
P9 = 109, // MICROBIT_ID_IO_P9
//% blockIdentity="pins.digitalPin"
P10 = 110, // MICROBIT_ID_IO_P10
//% blockIdentity="pins.digitalPin"
P11 = 111, // MICROBIT_ID_IO_P11
//% blockIdentity="pins.digitalPin"
P12 = 112, // MICROBIT_ID_IO_P12
//% blockIdentity="pins.digitalPin"
P13 = 113, // MICROBIT_ID_IO_P13
//% blockIdentity="pins.digitalPin"
P14 = 114, // MICROBIT_ID_IO_P14
//% blockIdentity="pins.digitalPin"
P15 = 115, // MICROBIT_ID_IO_P15
//% blockIdentity="pins.digitalPin"
P16 = 116, // MICROBIT_ID_IO_P16
//% blockIdentity="pins.digitalPin"
//% blockHidden=1
P19 = 119, // MICROBIT_ID_IO_P19
//% blockIdentity="pins.digitalPin"
//% blockHidden=1
P20 = 120, // MICROBIT_ID_IO_P20
}


declare const enum AnalogPin {
//% blockIdentity="pins.analogPin"
P0 = 100, // MICROBIT_ID_IO_P0
//% blockIdentity="pins.analogPin"
P1 = 101, // MICROBIT_ID_IO_P1
//% blockIdentity="pins.analogPin"
P2 = 102, // MICROBIT_ID_IO_P2
//% blockIdentity="pins.analogPin"
P3 = 103, // MICROBIT_ID_IO_P3
//% blockIdentity="pins.analogPin"
P4 = 104, // MICROBIT_ID_IO_P4
//% blockIdentity="pins.analogPin"
P10 = 110, // MICROBIT_ID_IO_P10
//% blockIdentity="pins.analogPin"
//% block="P5 (write only)"
P5 = 105, // MICROBIT_ID_IO_P5
//% blockIdentity="pins.analogPin"
//% block="P6 (write only)"
P6 = 106, // MICROBIT_ID_IO_P6
//% blockIdentity="pins.analogPin"
//% block="P7 (write only)"
P7 = 107, // MICROBIT_ID_IO_P7
//% blockIdentity="pins.analogPin"
//% block="P8 (write only)"
P8 = 108, // MICROBIT_ID_IO_P8
//% blockIdentity="pins.analogPin"
//% block="P9 (write only)"
P9 = 109, // MICROBIT_ID_IO_P9
//% blockIdentity="pins.analogPin"
//% block="P11 (write only)"
P11 = 111, // MICROBIT_ID_IO_P11
//% blockIdentity="pins.analogPin"
//% block="P12 (write only)"
P12 = 112, // MICROBIT_ID_IO_P12
//% blockIdentity="pins.analogPin"
//% block="P13 (write only)"
P13 = 113, // MICROBIT_ID_IO_P13
//% blockIdentity="pins.analogPin"
//% block="P14 (write only)"
P14 = 114, // MICROBIT_ID_IO_P14
//% blockIdentity="pins.analogPin"
//% block="P15 (write only)"
P15 = 115, // MICROBIT_ID_IO_P15
//% blockIdentity="pins.analogPin"
//% block="P16 (write only)"
P16 = 116, // MICROBIT_ID_IO_P16
//% blockIdentity="pins.analogPin"
//% block="P19 (write only)"
//% blockHidden=1
P19 = 119, // MICROBIT_ID_IO_P19
//% blockIdentity="pins.analogPin"
//% block="P20 (write only)"
//% blockHidden=1
P20 = 120, // MICROBIT_ID_IO_P20
Expand Down
Loading
Loading