RGB LED with color picker help

So I'm new to Arduino and have had my board for about a month now, and had some RGB LEDs that I wanted to fiddle around with. So I google a few things and found this site:

blog.bsoares.com.br/processing/controlling-rgb-led-with-arduino-and-processing
(Sorry for breaking rules and not adhereing to the "Cannot post links with no posts")

Though it's in spanish (I think?) I fingered out what was what pretty quickly. Now the LED it uses has four leads that consist of a cathode, and three anodes for the desired color output (+|-|+|+). However, that is not what I have. I have the exact opposite, one anode and three cathodes (-|+|-|-).

Since this project requires that the digital PWM pin be, simply put, positive; is there anyway code-wise that I swap +5 to -5? Or rather, how can I switch up the code in this guys page. Note that I'm still learning the Arduino language, but I'm well versed in electronics, so explain code if you post any.

Thanks!

Hmm that poses an interesting question. I have no idea how you could control the three colors separately without a common cathode.. All I can think that you could do is produce varying intensities of one color mixed or a variable intensity of all three colors mixed...

That's a strange way to do a tri-color LED in my opinion..

I bought my LEDs at a local electronics surplus shop, which should have alerted me to something odd in the first place. But when I started to look around for common cathode RGBs, I noticed Adafruit sells the odd ones too. I was going to check Sparkfun but they're down for maintenance. I figured there wouldn't be a way to drive these easily, so I immediately thought "should have bought the right part in the first place". But I'm also interested in whether this can be done or not.

It’s all the same really. Tie your one anode to +V and run the 3 cathodes thru resistors to the pwm pins.

It's all the same really. Tie your one anode to +V and run the 3 cathodes thru resistors to the pwm pins.

Care to elaborate? :stuck_out_tongue:

I tried that in the first place which led to me figuring out that the pinouts were swapped. You can't attach + to - and - to + and expect something to work, that much I've learned.

EDIT: I see what you're saying, and I got it to work, sort of.

I got it all connected, now here's the issue. The color I select in Processing is the color that is off on the LED. So if I choose a solid red. I get blue and green. What's wrong with this now?

its inverted

;D I know that, but how do I swap it since I'm powering it backwards?

With a common anode LED you have to sink the current to turn it on. With a common cathode you have to source the current to turn it on.

In fact the common anode is the more common type.

The difference between source and sinking is that the LED is turned on fully with a logic one (source) or full on with a logic zero (sink).

This means that the PWM works the reverse way round for each type.
If you want to invert it, it is quite simple to do this in software. In place of writing a variable n to the:-
analogueWrite(pin,n);
simply write a value of:-
analogueWrite(pin,255-n);