voodootikigod / voodoospark

A RPC based firmware for a Spark Core device (like being connected, but without the wire!)
MIT License
145 stars 35 forks source link

Add special pin address to control main RGB #31

Closed Resseguie closed 9 years ago

Resseguie commented 10 years ago

I'd like to be able to control the main RGB on the Spark. The Spark core firmware provides an RGB class for this but it doesn't seem to be mapped to a pin.

Could we assign a special pin address (255?) that is mapped to the RGB behind the scenes in voodoospark?

My use case: I just want to be able to turn it off once I connect using spark-io because I'm physically embedding the Spark with a standard RGB inside a little light (think mood light) and the flashing cyan overpowers the colors I'm setting.

rwaldron commented 10 years ago

RGBClass methods:

This is really messy.

Resseguie commented 10 years ago

I wonder how they actually handle brightness, since just dimming it can actually change the color if you aren't careful. I'll have to re-load the standard firmware and test it.

(That's exactly why I took it out of Johnny-Five's Led.RGB class for now until I figure out the best way to calculate it.)

rwaldron commented 10 years ago

I wonder how they actually handle brightness, since just dimming it can actually change the color if you aren't careful. I'll have to re-load the standard firmware and test it.

I'm curious to know this as well, unfortunately all signs lead back to LED_SetBrightness which apparently has no definition anywhere in that repo :(

rwaldron commented 10 years ago

Based on your tweet we could start simple by mapping board.digitalWrite(255, 1|0) to on and off

canda commented 9 years ago

@Resseguie thanks for the link, I didn't see this ticket. Brightness may be handled just lowering the numbers of red green and blue proportionally.

rgb(255,255,255) => white (1/full bright)
rgb(128,128,128) => grey (0.5/half bright)
rgb(0,0,0) => black (0/null bright)

rgb(255,0,0)=>bright red (1/full bright)
rgb(128,0,0)=>dark red (0.5/half bright)
rgb(0,0,0) => black (0/null bright)

And so on

I don't know if it is the best implementation, but the quickest I found to get to the point. I posted a pull request.

I have tested through the spark-io library and worked for me

canda commented 9 years ago

I selected the first byte arbitrarily. But i saw there was a gap defined in the array of first bytes. Does it have any special reason?

Resseguie commented 9 years ago

@canda reducing brightness by lowering RGB values proportionally "kinda" works. Those examples you provided are for pure colors. The difficulty is in mixed values.

canda commented 9 years ago

@Resseguie you need multiply each color value by a factor Lets say you have this strange brown color

rgb(190,155,123) => http://www.color-hex.com/color/be9b7b

And you want to make it 52% darker, then the factor would be 0.48 190 x 0.48 = 91 155 x 0.48 = 74 123 x 0.48 = 59

so we got a darker shade of the same brown

rgb(91,74,59) => http://www.color-hex.com/color/5b4a3b

Resseguie commented 9 years ago

Fixed by #40 and related spark-io additions.