Skip to content

Commit

Permalink
feat: add digital multiplexer block (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoesbergen authored Dec 7, 2024
1 parent 0618866 commit 7b7867d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist",
"media"
],
"version": "3.2.6",
"version": "3.3.0",
"description": "Leaphy custom Blockly blocks and arduino code generator",
"name": "@leaphy-robotics/leaphy-blocks"
}
24 changes: 24 additions & 0 deletions src/blocks/leaphy_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ const blocks: BlockDefinition = [
style: "leaphy_blocks",
helpUrl: "http://arduino.cc/en/Reference/DigitalWrite",
},
{
type: "leaphy_multiplexer_digitalwrite",
message0: "%%{BKY_ARD_SET_MULTIPLEXER} %1",
args0: [
{
type: "field_dropdown",
name: "PIN",
options: [
["Y0", "0"],
["Y1", "1"],
["Y2", "2"],
["Y3", "3"],
["Y4", "4"],
["Y5", "5"],
["Y6", "6"],
["Y7", "7"],
],
},
],
inputsInline: true,
previousStatement: null,
nextStatement: null,
style: "leaphy_blocks",
},
{
type: "leaphy_io_analogwrite",
message0: "%%{BKY_ARD_ANALOGWRITE} %1 %%{BKY_ARD_WRITE_TO} %2",
Expand Down
16 changes: 16 additions & 0 deletions src/generators/arduino/leaphy_extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ function getCodeGenerators(arduino: Arduino) {
return `analogWrite(${pin}, ${stateOutput});\n`;
};

arduino.forBlock["leaphy_multiplexer_digitalwrite"] = function (block) {
const pin = block.getFieldValue("PIN");

const pinSetupCode =
"pinMode(0, OUTPUT);\n" +
" pinMode(16, OUTPUT);\n" +
" pinMode(1, OUTPUT);\n";
arduino.addSetup("dgmulti", pinSetupCode, false);

return (
`digitalWrite(0, bitRead(${pin}, 2));\n` +
`digitalWrite(16, bitRead(${pin}, 1));\n` +
`digitalWrite(1, bitRead(${pin}, 0));\n`
);
};

arduino.forBlock["leaphy_sonar_read"] = function (block) {
arduino.addInclude("leaphy_extra", '#include "Leaphy_Extra.h"');
const trigPin = block.getFieldValue("TRIG_PIN");
Expand Down
1 change: 1 addition & 0 deletions src/msg/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ messages["ACTUATOREN_CATEGORY"] = "Actuators";
messages["ADD_COMMENT"] = "Add Comment";
messages["ARD_ANALOGWRITE"] = "Set PWM pin";
messages["ARD_DIGITALWRITE"] = "Set digital pin";
messages["ARD_SET_MULTIPLEXER"] = "Set digital multiplexer to pin";
messages["ARD_PIN_WARN1"] =
"Pin %1 is needed for %2 as pin %3. Already in use as %4.";
messages["ARD_SERVO_READ"] = "Read servo pin";
Expand Down
1 change: 1 addition & 0 deletions src/msg/translations/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ messages["ACTUATOREN_CATEGORY"] = "Actuatoren";
messages["ADD_COMMENT"] = "Opmerking toevoegen";
messages["ARD_ANALOGWRITE"] = "Zet PWM";
messages["ARD_DIGITALWRITE"] = "Zet Digipin";
messages["ARD_SET_MULTIPLEXER"] = "Stel digitale multiplexer in op pin";
messages["ARD_PIN_WARN1"] =
"Pin %1 is nodig voor %2 als pin %3. Al gebruikt als %4.";
messages["ARD_SERVO_READ"] = "Lees servo pin";
Expand Down

0 comments on commit 7b7867d

Please sign in to comment.