O'Reilly logo

Mastering Arduino by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RGB LED

We will start off by defining which pins on the Arduino are connected to the RGB pins on the LED:

#define REDPIN 11
#define BLUEPIN 10
#define GREENPIN 9

This code shows that the red pin is connected to the Arduino 11 PWM pin, the blue pin is connected to the Arduino 10 PWM pin and the green pin is connected to the Arduino 9 PWM pin. We are going to define an empty macro that will let the application code know whether we have a common anode or a common cathode RGB LED. The following code will do that:

#define COMMON_ANODE

If you are using a common cathode RGB LED, then comment or remove this line from your code. We will see how to use this when we look at the function that sets the colors of the LED. Now let's look at the setup() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required