mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
let Arduino node only send changes of values as stated in docs.
This commit is contained in:
parent
e57e2545d6
commit
5019f68c9c
@ -56,24 +56,34 @@ module.exports = function(RED) {
|
||||
if (typeof this.serverConfig === "object") {
|
||||
this.board = this.serverConfig.board;
|
||||
var node = this;
|
||||
node.oldval = "";
|
||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"});
|
||||
var doit = function() {
|
||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||
if (node.state === "ANALOG") {
|
||||
node.board.pinMode(node.pin, 0x02);
|
||||
node.board.analogRead(node.pin, function(v) {
|
||||
node.send({payload:v, topic:"A"+node.pin});
|
||||
if (v !== node.oldval) {
|
||||
node.oldval = v;
|
||||
node.send({payload:v, topic:"A"+node.pin});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (node.state === "INPUT") {
|
||||
node.board.pinMode(node.pin, 0x00);
|
||||
node.board.digitalRead(node.pin, function(v) {
|
||||
node.send({payload:v, topic:node.pin});
|
||||
if (v !== node.oldval) {
|
||||
node.oldval = v;
|
||||
node.send({payload:v, topic:node.pin});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (node.state == "STRING") {
|
||||
node.board.on('string', function(v) {
|
||||
node.send({payload:v, topic:"string"});
|
||||
if (v !== node.oldval) {
|
||||
node.oldval = v;
|
||||
node.send({payload:v, topic:"string"});
|
||||
}
|
||||
});
|
||||
}
|
||||
// node.board.on('close', function() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-arduino",
|
||||
"version" : "0.0.14",
|
||||
"version" : "0.0.15",
|
||||
"description" : "A Node-RED node to talk to an Arduino running firmata",
|
||||
"dependencies" : {
|
||||
"firmata" : "~0.17.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user