1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Better error handling for Pibrella buzzer. (and more useful).

This commit is contained in:
Dave C-J 2014-04-03 12:39:52 +01:00
parent 842d3e3c7e
commit 36bbddffe5
2 changed files with 7 additions and 4 deletions

View File

@ -85,7 +85,7 @@
<script type="text/x-red" data-help-name="rpi-pibrella out">
<p>Raspberry Pi Pibrella output node. The Pibrella board must be fitted.</p>
<p>Will set the selected output high (on) or low (off) depending on the value passed in. Expects a <b>msg.payload</b> with either a 0 or 1 (or true or false).</p>
<p>The Buzzer is a divider so low numbers are high notes. 0 is off, and the sensible lowest note is around 250-300.</p>
<p>The Buzzer is a divider so low numbers are high notes. 0 is off, and the sensible lowest note is around 250-300. 2 is the highest note. 1 is just a buzz (so you can use 0/1 type inputs).</p>
<p>Requires the WiringPi gpio command in order to work.</p>
</script>

View File

@ -107,12 +107,15 @@ function PibrellaOut(n) {
exec("gpio pwm-ms");
node.on("input", function(msg) {
var out = Number(msg.payload);
if (out == 1) { out = 2; } // doesn't work with 1...
if (out == 0) { exec("gpio pwm 1 0"); }
else {
if (out == 1) { // fixed buzz
exec("gpio pwm 1 511");
exec("gpio pwmc 100");
}
else if ((out >= 2) && (out <= 9999)) { // set buzz to a value
exec("gpio pwm 1 511");
exec("gpio pwmc "+out);
}
else { exec("gpio pwm 1 0"); } // turn it off
});
});
}