Merge pull request #237 from sensebox/dev/button_asSwitch

add Button as Switch
This commit is contained in:
Mario Pesch 2023-04-03 12:35:07 +02:00 committed by GitHub
commit abce42f764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -336,6 +336,7 @@ Blockly.Blocks["sensebox_button"] = {
[Blockly.Msg.senseBox_button_isPressed, "isPressed"],
[Blockly.Msg.senseBox_button_wasPressed, "wasPressed"],
[Blockly.Msg.senseBox_button_longPress, "longPress"],
[Blockly.Msg.senseBox_button_switch,"toggleButton"]
]),
"FUNCTION"
)

View File

@ -399,6 +399,7 @@ Blockly.Arduino.sensebox_button = function () {
Blockly.Arduino.libraries_[
"library_jcButtons"
] = `#include <JC_Button.h> // http://librarymanager/All#JC_Button`;
Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] =
"Button button_" + dropdown_pin + "(" + dropdown_pin + ");";
Blockly.Arduino.setupCode_["setup_button" + dropdown_pin + ""] =
@ -413,6 +414,10 @@ Blockly.Arduino.sensebox_button = function () {
} else if (dropown_function === "longPress") {
var time = this.getFieldValue("time");
code = "button_" + dropdown_pin + ".pressedFor(" + time + ")";
} else if (dropown_function === "toggleButton") {
code = "button_" + dropdown_pin + ".toggleState()";
Blockly.Arduino.definitions_["define_button" + dropdown_pin + ""] =
"ToggleButton button_" + dropdown_pin + "(" + dropdown_pin + ");";
}
return [code, Blockly.Arduino.ORDER_ATOMIC];
};