Color light with RGB LEDs

When you first started with exercise 1, you were happy to just flash the LED. But you transcended that, didn't you? You want orange, you want teal, eggplant! Luckily, there's a way to make multiple colours shine with a single LED without having to align every shade of rainbow in the sky. For this we will use LED RGB.
LED RGB is not just an LED - it is actually three LEDs in one package: red, green and blue. When you turn them on, their light mixes and you get other colors. The color you get is the result of the intensity of the individual red, green and blue LEDs. The intensity is controlled by pulse width modulation (MLI), or PWM (Pulse Width Modulation) in English, which we previously reviewed with the brightness of the LED indicator and engine speed.

COMPONENTS

CIRCUIT DIAGRAM

Schéma du circuit

CIRCUIT INSTALLATION

Diagramme d'assemblage

Montage d'une LED RVB
RGB LED installation by translator

CODE

You can find this code in CIRC-12-code-led-rgb.js

var j5 = require("johnny-five");

j5.Board().on("ready", function() {
  var myLed = new j5.Led.RGB([ 9, 10, 11 ]);
  // rend le voyant rouge
  myLed.color("#ff0000");
  this.wait(1000, function() {
    // rend le voyant bleu après 1 seconde
    myLed.color("#00ff00");
  });

  this.wait(2000, function(){
    // rend le voyant vert après 2 secondes
    myLed.color("#0000ff");
  });

  this.wait(3000, function(){
    // éteint le voyant après 3 secondes
    myLed.off();
  });

  this.repl.inject({
    r: myLed
  });
});

EMERGENCY REPAIR

LED remains black or shows incorrect color

With four-pin LEDs, so close together, it is sometimes difficult to place one of them. Make sure each contact is where it should be.

See red

The red diode among RGB LEDs may be slightly brighter than the other two. To make their colors more swayed, use a transistor with more ohms or adjust the red value in the code.

CODE EXTENSION

Distribution land

The disadvantage of using LED RGBs from three separate LEDs to generate our colors is that sometimes you can see the colors of three separate lights. One way to avoid this is to make light more diffuse (or diffuse) spells so that individual colors blend better. Many LED RGBs are broadcast rather than clean to help improve the quality of the color mix. If the light is not sufficiently diffused, you can try placing the LED behind a sheet of paper or acrylic; or in ping-pong or in polystyrene.