Control RGB Led with joystick

Hello,

Recently i bought this joystick http://www.miniinthebox.com/nl/arduino-joystick-module-201211270080028_p480356.html so i could control the colors of my RGB leds witht it. But now i've got it, i don't remember where i found the code and i can't find it anymore. Does anyone have an tutorial to control LEDs with an joystick like the one i bought?

That joystick only has two degrees of freedom. To control an RGB LED you need three degrees of freedom so you can not fully control the colour you produce fully with just one joystick.

Grumpy_Mike:
you can not fully control the colour you produce fully with just one joystick.

Sure you can. Just map your joystick position to a "color wheel".

eg. One of these two:

Yes you can. Just map your joystick position to a "color wheel".

No you can't!!
Mapping a colour wheel to a joystick only gives you control of two parameters no matter what colour space you are in.
You can not get all the colours from just two parameters.
You show two wheels in that picture, you can only map one of those wheels with one joystick. That leaves the other wheel and the colours not mapped to the joystick.
What that picture is showing is HSV colour space, there are three parameters to that colour space and with a joystick you only have two parameters you can change.

Therefore you can not get FULL control over colour with a joystick.

Pedant... :astonished:

That particular joystick has a push-button built into it. You can do complete control if you combine button with position.

fungus:
That particular joystick has a push-button built into it. You can do complete control if you combine button with position.

No you can't.
You don't seem to understand about colour space and parameters, please take some time to try and learn before offering bogus advice.

fungus:
Pedant... :astonished:

Well it is better than being like you - WRONG!!!

Well he could map some of the colours with the joystick...

Use
UP=Red
Down=Green
Left=Blue
Right=Red+Green (Yellow)

That would give centre=OFF .. you could also have centre=ON(White) and each direction is Minus the colours listed above.

Anyway, good luck :slight_smile:

Well he could map some of the colours with the joystick..

Yes I would agree with that.

well,
does anyone have some code so i can test it?

Arjan901:
well,
does anyone have some code so i can test it?

No but here's a rough idea. Check the example in the IDE that reads a potentiometer: File > Examples > Analog > AnalogInput.

That's exactly how a joystick works, except there are two of them, so double up the code with appropriate pin and variable name adjustments.

Then use map to cause the analog reading of 0-1023 to give you a colour of 0-255. Have a look at the IDE example File > Examples > Servo > Knob for a clue for that, except the servo uses map to go from 0-179. Borrow that line but make 179 into 255. Or, just divide the joystick analog by 4, that's easier.

Then set one colour to a value of your choice, and use the joystick's output to drive the other two.

Grumpy_Mike:

fungus:
That particular joystick has a push-button built into it. You can do complete control if you combine button with position.

No you can't.
You don't seem to understand about colour space and parameters, please take some time to try and learn before offering bogus advice.

LOL! Color spaces are my real job (well, part of it....)

Grumpy_Mike:

fungus:
Pedant... :astonished:

Well it is better than being like you - WRONG!!!

What I originally meant was: You can map a very useful percentage of the RGB color space with just a two-axis joystick.

And if you use the push button to toggle between control of variables in HSV space (eg. 'H' & 'SV') you can do all of it (within the limits of ADC accuracy).