mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
slight tidy to Arduino and bump version
This commit is contained in:
parent
f676005cad
commit
dc3b220ec4
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2013,2015 IBM Corp.
|
||||
Copyright 2013,2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -18,10 +18,6 @@
|
||||
<label for="node-input-arduino"><i class="fa fa-tasks"></i> Arduino</label>
|
||||
<input type="text" id="node-input-arduino">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
|
||||
<input type="text" id="node-input-pin" placeholder="2">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-state"><i class="fa fa-wrench"></i> <span data-i18n="arduino.label.type"></span></label>
|
||||
<select type="text" id="node-input-state" style="width: 150px;">
|
||||
@ -30,6 +26,10 @@
|
||||
<option value="STRING" data-i18n="arduino.state.in.string"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
|
||||
<input type="text" id="node-input-pin" placeholder="2">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
@ -51,7 +51,10 @@
|
||||
color:"#3fadb5",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
pin: {value:"",required:true},
|
||||
pin: {value:"",validate: function(v) {
|
||||
var ct = $("#node-input-state").val() || this.state;
|
||||
return ct === 'STRING' || (v != '');
|
||||
}},
|
||||
state: {value:"INPUT",required:true},
|
||||
arduino: {type:"arduino-board"}
|
||||
},
|
||||
@ -59,6 +62,7 @@
|
||||
outputs:1,
|
||||
icon: "arduino.png",
|
||||
label: function() {
|
||||
if (this.state === "STRING") { return "String"; }
|
||||
var a = "";
|
||||
if (this.state === "ANALOG") { a = "A"; }
|
||||
return this.name||"Pin: "+a+this.pin;
|
||||
@ -74,10 +78,6 @@
|
||||
<label for="node-input-arduino"><i class="fa fa-tasks"></i> <span data-i18n="arduino.label.arduino"></span></label>
|
||||
<input type="text" id="node-input-arduino">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
|
||||
<input type="text" id="node-input-pin" placeholder="13">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-state"><i class="fa fa-wrench"></i> <span data-i18n="arduino.label.type"></span></label>
|
||||
<select type="text" id="node-input-state" style="width: 200px;">
|
||||
@ -87,6 +87,10 @@
|
||||
<option value="STRING" data-i18n="arduino.state.out.string"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="fa fa-circle"></i> <span data-i18n="arduino.label.pin"></span></label>
|
||||
<input type="text" id="node-input-pin" placeholder="13">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||
@ -108,7 +112,10 @@
|
||||
color:"#3fadb5",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
pin: {value:"",required:false},
|
||||
pin: {value:"",validate: function(v) {
|
||||
var ct = $("#node-input-state").val() || this.state;
|
||||
return ct === 'STRING' || (v != '');
|
||||
}},
|
||||
state: {value:"",required:true},
|
||||
arduino: {type:"arduino-board"}
|
||||
},
|
||||
@ -117,6 +124,7 @@
|
||||
icon: "arduino.png",
|
||||
align: "right",
|
||||
label: function() {
|
||||
if (this.state === "STRING") { return "String"; }
|
||||
return this.name||"Pin: "+this.pin;
|
||||
},
|
||||
labelStyle: function() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2013,2015 IBM Corp.
|
||||
* Copyright 2013,2016 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -134,10 +134,10 @@ module.exports = function(RED) {
|
||||
node.board.on('connect', function() {
|
||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||
//console.log("o",node.state,node.pin);
|
||||
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (node.state === "OUTPUT") {
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
if ((msg.payload === true)||(msg.payload.toString() == "1")||(msg.payload.toString().toLowerCase() == "on")) {
|
||||
node.board.digitalWrite(node.pin, true);
|
||||
}
|
||||
@ -146,14 +146,14 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
if (node.state === "PWM") {
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
msg.payload = parseInt((msg.payload * 1) + 0.5);
|
||||
if ((msg.payload >= 0) && (msg.payload <= 255)) {
|
||||
node.board.analogWrite(node.pin, msg.payload);
|
||||
}
|
||||
}
|
||||
if (node.state === "SERVO") {
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
node.board.pinMode(node.pin, node.state);
|
||||
msg.payload = parseInt((msg.payload * 1) + 0.5);
|
||||
if ((msg.payload >= 0) && (msg.payload <= 180)) {
|
||||
node.board.servoWrite(node.pin, msg.payload);
|
||||
|
@ -23,7 +23,7 @@ details and examples of how to use this node.
|
||||
|
||||
Connects to local Arduino and monitors the selected pin for changes.
|
||||
|
||||
You can select either **Digital** or **Analogue** input type.
|
||||
You can select either **Digital**, **Analogue**, or **String** input type.
|
||||
Outputs the value read as `msg.payload` and the pin number as `msg.topic`.
|
||||
|
||||
It only outputs on a change of value - fine for digital inputs, but you can get a lot of data from analogue pins which you must then handle.
|
||||
@ -39,6 +39,7 @@ You can select
|
||||
- **Digital** - accepts 0, 1, true, false, on, off
|
||||
- **Analogue** (PWM) - accepts Integer 0 to 255
|
||||
- **Servo** - accepts Integer 0 - 180
|
||||
- **String** - to send a *String* to the Arduino
|
||||
|
||||
Expects a numeric value in `msg.payload`. The pin number is set in the properties panel.
|
||||
|
||||
|
@ -19,13 +19,13 @@
|
||||
"in": {
|
||||
"digital": "Digital pin",
|
||||
"analogue": "Analogue pin",
|
||||
"string": "String"
|
||||
"string": "String"
|
||||
},
|
||||
"out": {
|
||||
"digital": "Digital (0/1)",
|
||||
"analogue": "Analogue (0-255)",
|
||||
"servo": "Servo (0-180)",
|
||||
"string": "String"
|
||||
"string": "String"
|
||||
}
|
||||
},
|
||||
"tip": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user