mirror of
https://github.com/xodio/xod.git
synced 2026-03-24 01:26:53 +01:00
feat(workspace): implement servo node
This commit is contained in:
24
workspace/lib/xod/common-hardware/servo/arduino.cpp
Normal file
24
workspace/lib/xod/common-hardware/servo/arduino.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
{{#global}}
|
||||
#include <Servo.h>
|
||||
{{/global}}
|
||||
|
||||
struct State {
|
||||
Servo servo;
|
||||
int configuredPort = -1;
|
||||
};
|
||||
|
||||
{{ GENERATED_CODE }}
|
||||
|
||||
void evaluate(NodeId nid, State* state) {
|
||||
if (!isInputDirty<Inputs::UPD>(nid))
|
||||
return;
|
||||
|
||||
auto port = (int)getValue<Inputs::PORT>(nid);
|
||||
if (port != state->configuredPort) {
|
||||
state->servo.attach(port);
|
||||
state->configuredPort = port;
|
||||
}
|
||||
|
||||
state->servo.write(getValue<Inputs::VAL>(nid) * 180);
|
||||
}
|
||||
50
workspace/lib/xod/common-hardware/servo/patch.xodp
Normal file
50
workspace/lib/xod/common-hardware/servo/patch.xodp
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user