Using RGB LED on TeensyWiNo

The TeensyWiNo shield embeds a RGB (Red Green Blue) LED. This tutorial explains how-to use this RGB LED to light colors on the TeensyWiNo.

Hardware

As we can see on the TeensyWiNo wiring, the RGB LED is wired on pins 5, 6 and 23.

  • Red color: pin #23
  • Green color: pin #5
  • Blue color: pin #6

On the Arduino sketch, the 3 pins must be declared as outputs. The following Language-C code enables the pin as outputs:

pinMode(23, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

Put these lines on the setup() function.

Please refer to the pinMode() page on the Arduino Manual to get more on this function.

Software

There are two ways to drive the RGB LED of the TeensyWiNo:

  1. Using boolean values (0% or 100%)
  2. Using PWM values (0% – 100%) to make color variations.

Each primary color can be individually activated: red, green or blue.

TeensyWiNo RGB LED Red-small TeensyWiNo RGB LED Green-small TeensyWiNo RGB LED Blue-small

While combining the two primary colors, three others colors can be achieved: Yellow, Cyan and Magenta.

TeensyWiNo RGB LED Yellow-small TeensyWiNo RGB LED Cyan-small TeensyWiNo RGB LED Magenta-small

If the three primary colors are active, the resulting color is white.

TeensyWiNo RGB LED White-small

Driving RGB LED with boolean values

The Arduino digitalWrite() function can be use to drive each primary colors Red, Green and Blue.

digitalWrite(5, HIGH); // turns the green component on
digitalWrite(6, LOW); // turns the blue component off

Please refer to the digitalWrite() page on the Arduino Manual to get more on this function.

Driving RGB LED with PWM

The Arduino analogWrite() function can also be use to drive the 3 primary colors Red, Green and Blue with a 8-bit level (from 0 to 255); thanks to the PWM signal, the level of luminosity can be set.

analogWrite(5, 255); // turns the green component on (100%)
analogWrite(6, 0); // turns the blue component off (0%)
analogWrite(23, 128); // turns the red component to 50%

Please refer to the analogWrite() page on the Arduino Manual to get more on this function.

The Teensy has advanced parameters for PWM driving. Please refer to the Pulsed Output: PWM & Tone tutorial on PJRC website.





Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply