Edition 2 - Challenge 3 - Fireworks Rate

Challenge:  Help Leddy and Reggie setup the fireworks rate based on the ambient temperature changes..

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 (D7, D8 and D9)

Connect one pin of the temperature sensor to the ground (GND) and the other pin to the analog input A4.

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 3

Title:     Fireworks Rate
Edition:   2
Challenge: 3
Author:    Stephane

Description: In this challenge, use a temperature sensor
to set the blinking rate of the RGB LED for 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(7);    // red on Digital Pin 7
  var blue = new five.Led(8);  // blue on Digital Pin 8
  var green = new five.Led(9); // green on Digital Pin 9

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

  // 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);
    }
  });

});