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() ...

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.