hybridgroup / cylon-gpio

Cylon drivers for GPIO devices
http://cylonjs.com
Other
19 stars 14 forks source link

RGB LED driver does not work correctly on Intel Edison #51

Open ArcanoxDragon opened 8 years ago

ArcanoxDragon commented 8 years ago

When using the RGB LED driver and the .setRGB() function, the PWM value is not set correctly. The MRAA specifications say that the Pwm.write() function takes a float value representing the percentage of the duty cycle, however the setRGB function parses the hexadecimal color code into three one-byte values ranging from 0-256 and passes those directly to the pwmWrite function. This means that the colors #FF0100 and #FFFF00 look identical.

This can be fixed by changing the following code (rgb-led.js:82-84):

this.connection.pwmWrite(this.redPin, val.r);
this.connection.pwmWrite(this.greenPin, val.g);
this.connection.pwmWrite(this.bluePin, val.b);

to this:

this.connection.pwmWrite(this.redPin, val.r / 256.0);
this.connection.pwmWrite(this.greenPin, val.g / 256.0);
this.connection.pwmWrite(this.bluePin, val.b / 256.0);

I'd be happy to make a pull request if this is determined to be an acceptable solution for this issue.

deadprogram commented 8 years ago

Hi, @briman0094 that certainly makes sense, and your PR would be appreciated.