Controlling RGB strip from Blynk on RPi3 w/ Node

Hello.

I’m new to Blynk and am trying to make a simple program to change the color of a generic RGB strip using mosfets and PWM. I’m using NodeJS and am having a hell of a time trying to get it to work.

Here is my code:

const raspi = require('raspi');
const pwm = require('raspi-soft-pwm');
var Blynk = require('blynk-library');

var AUTH = 'c4b73cf05d72463fb580f76bd251c354';

var blynk = new Blynk.Blynk(AUTH);

var r = new blynk.VirtualPin(1) * 0.00392157;
var g = new blynk.VirtualPin(2) * 0.00392157;
var b = new blynk.VirtualPin(3) * 0.00392157;

r.on('write', function(param) {
  raspi.init(() => {
    const ledr = new pwm.SoftPWM('GPIO20');
    ledr.write(r);
})});

g.on('write', function(param) {
  raspi.init(() => {
    const ledg = new pwm.SoftPWM('GPIO16');
    ledg.write(g);
})});

b.on('write', function(param) {
  raspi.init(() => {
    const ledb = new pwm.SoftPWM('GPIO21');
    ledb.write(b);
})});

And this is what I get when I try to run it:
/home/pi/ColorChanger/Colors.js:17
})};
^

SyntaxError: missing ) after argument list
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions…js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)

I have a basic understanding of code and most of the time can read through it and figure out what it is doing but Google is of no help with this error and I cannot find pre existing projects like what Im trying to do. Any and all help is greatly appreciated!

I no virtualy nothing about Node JS, but this error message seems fairly self explanatory:

If you count the number of open brackets “(“ and the number of close brackets “)” there’s a big discrepancy.
My guess is that if you fix that then you’ll be a lot closer to a solution.

Pete.

1 Like

I’ve already checked that and every open bracket has a closed one. So that is not it.

Your compiler disagrees with you :stuck_out_tongue_winking_eye: This is a “how to program and read syntax” issue, not Blynk specific.

Sometimes the compiler can be off track by another syntax issue, before or after the one it indicates… keep looking and compare with other similar lines.

PS Please properly format the code you post here…

Blynk - FTFC

Does your actual code look like this?

Thanks for the response, I’ve edited my original post to fix the code issue, I looked for a code section button but didn’t see it. And no my code does not have a rights reserved symbol in it.

And as far as syntax and whatnot, I’m at a lost for what it would be. I moved from typing the code on the RPi to using Notepad++ and everything looks right to me.

However if I don’t get a syntax error I get a binding file could not be found so I am going to try a different library and see if that helps.

I am still draggin my way through js… but I think I see a few things that don’t match my experience

r becomes the reference variable for V3 but why the math after?? Any data transferred via that vPin comes through under the param label here…

Thus I suspect a more correct way of doing whatever you are doing is…

ledr.write(param * 0.00392157);

PS, are single character variables, like r, g & b fine in js?? I like to use more relevant labeling.

My mistake, trying to count brackets while squinting at my phone screen (after a couple of beers) probably isn’t the best way to debug code.

As @Gunner said, there’s probably something else confusing the compiler.
You could try compiling the code in chunks, the declarations section first, then add back in just one of the code blocks and see what you get.

Pete.