diff --git a/workspace/lib/xod/common-hardware/servo/arduino.cpp b/workspace/lib/xod/common-hardware/servo/arduino.cpp new file mode 100644 index 00000000..2ac2a87f --- /dev/null +++ b/workspace/lib/xod/common-hardware/servo/arduino.cpp @@ -0,0 +1,24 @@ + +{{#global}} +#include +{{/global}} + +struct State { + Servo servo; + int configuredPort = -1; +}; + +{{ GENERATED_CODE }} + +void evaluate(NodeId nid, State* state) { + if (!isInputDirty(nid)) + return; + + auto port = (int)getValue(nid); + if (port != state->configuredPort) { + state->servo.attach(port); + state->configuredPort = port; + } + + state->servo.write(getValue(nid) * 180); +} diff --git a/workspace/lib/xod/common-hardware/servo/patch.xodp b/workspace/lib/xod/common-hardware/servo/patch.xodp new file mode 100644 index 00000000..cb2e9591 --- /dev/null +++ b/workspace/lib/xod/common-hardware/servo/patch.xodp @@ -0,0 +1,50 @@ +{ + "description": "", + "links": [], + "nodes": [ + { + "boundValues": {}, + "description": "", + "id": "HkaMmuTzZ", + "label": "UPD", + "position": { + "x": 266, + "y": 16 + }, + "type": "xod/patch-nodes/input-pulse" + }, + { + "boundValues": {}, + "description": "", + "id": "HkmSQOafZ", + "label": "", + "position": { + "x": 138, + "y": 120 + }, + "type": "xod/patch-nodes/not-implemented-in-xod" + }, + { + "boundValues": {}, + "description": "", + "id": "S1vGmu6Gb", + "label": "PORT", + "position": { + "x": 10, + "y": 16 + }, + "type": "xod/patch-nodes/input-number" + }, + { + "boundValues": {}, + "description": "", + "id": "r1sfQ_6fb", + "label": "VAL", + "position": { + "x": 138, + "y": 16 + }, + "type": "xod/patch-nodes/input-number" + } + ] +}