From e033b729129d6ebb1f902186bf8f32eb51af1c3c Mon Sep 17 00:00:00 2001 From: Gol Date: Thu, 13 Mar 2014 06:09:02 +0400 Subject: [PATCH] Added setFreq --- motorshield/motorshield.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/motorshield/motorshield.js b/motorshield/motorshield.js index 428a49c..2ef64e1 100644 --- a/motorshield/motorshield.js +++ b/motorshield/motorshield.js @@ -28,10 +28,20 @@ exports.setDivider = function (value) { divider = value; freq = parseInt(25000000 / (divider + 1) / 4096); tic = 1 / freq / 4096; - + fs.writeFileSync("/sys/bus/i2c/devices/1-00" + address.toString(16) + "/freq", divider); console.log("freq divider set to " + value); } +/* set I2C PWM frequency */ +exports.setFreq = function (value) { + freq = value; + divider = Math.round(25000000 / (4096 * freq)) -1; + tic = 1 / freq / 4096; + fs.writeFileSync("/sys/bus/i2c/devices/1-00" + address.toString(16) + "/freq", divider); + console.log("freq set to " + value); +} + + /* motorshield init */ exports.init = function () {