mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Tidy up arduino node slightly and update settings example to work nicer
with JohnnyFive
This commit is contained in:
		| @@ -18,7 +18,6 @@ module.exports = function(RED) { | ||||
|     "use strict"; | ||||
|     var ArduinoFirmata = require('arduino-firmata'); | ||||
|     var fs = require('fs'); | ||||
|     var plat = require('os').platform(); | ||||
|     var portlist = ArduinoFirmata.list(function (err, ports) { | ||||
|         portlist = ports; | ||||
|     }); | ||||
| @@ -32,7 +31,7 @@ module.exports = function(RED) { | ||||
|         var node = this; | ||||
|         node.board = new ArduinoFirmata(); | ||||
|         if (portlist.indexOf(node.device) === -1) { | ||||
|             node.warn("device "+node.device+" not found"); | ||||
|             node.error("device "+node.device+" not found"); | ||||
|         } | ||||
|         else { | ||||
|             node.board.connect(node.device); | ||||
| @@ -66,10 +65,8 @@ module.exports = function(RED) { | ||||
|         this.serverConfig = RED.nodes.getNode(this.arduino); | ||||
|         if (typeof this.serverConfig === "object") { | ||||
|             this.board = this.serverConfig.board; | ||||
|             //this.repeat = this.serverConfig.repeat; | ||||
|             var node = this; | ||||
|             node.status({fill:"red",shape:"ring",text:"connecting"}); | ||||
|  | ||||
|             node.board.on('connect', function() { | ||||
|                 node.status({fill:"green",shape:"dot",text:"connected"}); | ||||
|                 //console.log("i",node.state,node.pin); | ||||
| @@ -80,9 +77,8 @@ module.exports = function(RED) { | ||||
|                             node.send(msg); | ||||
|                         } | ||||
|                     }); | ||||
|  | ||||
|                 } | ||||
|                 else { | ||||
|                 if (node.state == "INPUT") { | ||||
|                     node.board.pinMode(node.pin, ArduinoFirmata.INPUT); | ||||
|                     node.board.on('digitalChange', function(e) { | ||||
|                         if (e.pin == node.pin) { | ||||
| @@ -91,6 +87,12 @@ module.exports = function(RED) { | ||||
|                         } | ||||
|                     }); | ||||
|                 } | ||||
|                 if (node.state == "SYSEX") { | ||||
|                     node.board.on('sysex', function(e) { | ||||
|                         var msg = {payload:e, topic:"sysex"}; | ||||
|                         node.send(msg); | ||||
|                     }); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|         else { | ||||
| @@ -118,7 +120,7 @@ module.exports = function(RED) { | ||||
|                 //console.log("o",node.state,node.pin); | ||||
|                 node.board.pinMode(node.pin, node.state); | ||||
|                 node.on("input", function(msg) { | ||||
|                     if (node.state == "OUTPUT") { | ||||
|                     if (node.state === "OUTPUT") { | ||||
|                         if ((msg.payload == true)||(msg.payload == 1)||(msg.payload.toString().toLowerCase() == "on")) { | ||||
|                             node.board.digitalWrite(node.pin, true); | ||||
|                         } | ||||
| @@ -126,20 +128,21 @@ module.exports = function(RED) { | ||||
|                             node.board.digitalWrite(node.pin, false); | ||||
|                         } | ||||
|                     } | ||||
|                     if (node.state == "PWM") { | ||||
|                     if (node.state === "PWM") { | ||||
|                         msg.payload = msg.payload * 1; | ||||
|                         if ((msg.payload >= 0) && (msg.payload <= 255)) { | ||||
|                             //console.log(msg.payload, node.pin); | ||||
|                             node.board.analogWrite(node.pin, msg.payload); | ||||
|                         } | ||||
|                     } | ||||
|                     if (node.state == "SERVO") { | ||||
|                     if (node.state === "SERVO") { | ||||
|                         msg.payload = msg.payload * 1; | ||||
|                         if ((msg.payload >= 0) && (msg.payload <= 180)) { | ||||
|                             //console.log(msg.payload, node.pin); | ||||
|                             node.board.servoWrite(node.pin, msg.payload); | ||||
|                         } | ||||
|                     } | ||||
|                     if (node.state === "SYSEX") { | ||||
|                         node.board.sysex(msg.payload); | ||||
|                     } | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
|   | ||||
| @@ -132,7 +132,7 @@ module.exports = { | ||||
|         // os:require('os'), | ||||
|         // bonescript:require('bonescript'), | ||||
|         // jfive:require("johnny-five"), | ||||
|         // jboard:require("johnny-five").Board() | ||||
|         // j5board:require("johnny-five").Board({repl:false}) | ||||
|     }, | ||||
|      | ||||
|      | ||||
|   | ||||
		Reference in New Issue
	
	Block a user