Edition 2 - Challenge 2 - Fireworks Intensity

Challenge:  Help Leddy and Reggie setup the fireworks intensity based on the potentiometer value.

Place your components

Place your potentiometer on the breadboard across the middle.

Place your RGB LED somewhere on your breadboard and add three 330 Ohms resistors (orange-orange-brown-gold).  Make sure the resistors are across the middle of the breadboard.

Place your wires

First, connect the cathode of the RGB LED (the longest lead) to the ground (see straight wire going from the LED to the GND header).

Next connect each resistor to a digital output (D9, D10 and D11)

Connect the lower pin of the potentiometer to the power supply (5V), the middle pin to the analog input A5 and the top pin to the ground (GND header).

Your code

Use your editor to create your program.  Use "nano" on Mac or "notepad" on PC.  You can give your script (program) the name you want.  Make sure to use the same name when you execute it with node.

The comments in the code (the parts in grey) are not necessary, but they will help you understand the code better.  Having problem with this challenge?  Let me know about it by filling this form.

/* Welcome to Edition 2, Challenge 2

Title:     Fireworks Intensity
Edition:   2
Challenge: 2
Author:    Stephane

Description: In this challenge, use a potentiometer
to set the intensity of the RGB LED and the different
colors.
*/

// Setup the johnny-five library
var five = require('johnny-five');
var board = new five.Board();

// Execute this function when the board is ready
board.on('ready', function() {

  // Define the RGB LED
  var red = new five.Led(9);    // red on Digital Pin 9
  var blue = new five.Led(10);  // blue on Digital Pin 10
  var green = new five.Led(11); // green on Digital Pin 11

  // Define the sensor
  var pot = new five.Sensor("A5"); // Pot on Analog Pin A5

  // Execute this function when the sensor value changes
  pot.on("change", function() {

    console.log('value=' + this.value ); // send message

    // adjust the values based on your tests
    if ( this.value > 460 ) {
      red.blink(this.value);
    } else if ( this.value > 430 ) {
      blue.blink(this.value);
    } else if ( this.value > 410) {
      green.blink(this.value);
    }
  });

});