触摸+舵机

本示例介绍了如何使用SmartNode驱动触摸模块和舵机模块,实现用触摸传感器控制舵机转动的效果。

首先硬件接线图如下:

176

触摸传感器模块插在D2接口,舵机模块插在PWM D3接口。

SmartNode中用到的node有:触摸传感器节点、判断/切换节点、改变节点、舵机控制节点。

程序设计如下:

177

相关节点的配置如下:

178

179

180

181

182

配置完成后,点击右上角的部署(Deploy)按钮。当触摸传感器显示为turn on时,舵机转到100度的位置;当触摸传感器显示为turn off时,舵机转到30度的位置。

 

整个程序的json代码如下:

[{“id”:”d1ac7f8e.2e538″,”type”:”DF-Touch”,”z”:”6b3d036d.94c2fc”,”name”:”Touch”,”digitalPin”:”2″,”impulse”:”500″,”x”:90,”y”:180,”wires”:[[“3698a349.c9675c”]]},{“id”:”3698a349.c9675c”,”type”:”switch”,”z”:”6b3d036d.94c2fc”,”name”:””,”property”:”payload”,”rules”:[{“t”:”eq”,”v”:”1″},{“t”:”eq”,”v”:”0″}],”checkall”:”true”,”outputs”:2,”x”:248,”y”:181,”wires”:[[“3eff50e5.c100b”],[“da975a09.2568a8”]]},{“id”:”3eff50e5.c100b”,”type”:”change”,”z”:”6b3d036d.94c2fc”,”name”:”旋转到100″,”rules”:[{“t”:”set”,”p”:”payload”,”to”:”100″}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:414,”y”:147,”wires”:[[“48362b53.b7c9d4”]]},{“id”:”da975a09.2568a8″,”type”:”change”,”z”:”6b3d036d.94c2fc”,”name”:”旋转到30″,”rules”:[{“t”:”set”,”p”:”payload”,”to”:”30″}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:412,”y”:212,”wires”:[[“48362b53.b7c9d4”]]},{“id”:”48362b53.b7c9d4″,”type”:”DF-Servo”,”z”:”6b3d036d.94c2fc”,”name”:”Servo”,”pwmPin”:”3″,”x”:579,”y”:178,”wires”:[[]]}]

跳至工具栏