Edition 2 - Challenge 4 - Fireworks Grand Finale

Challenge:  This is the final firework display.  Bring all the skills you learned in a single project.  There will be a lot of wires and this challenge is the most difficult yet.  You will need both breadboards for this challenge.  Use the prototype shield for your RGB LEDs, and your new breadboard for the controls.

Take a step by step approach.  First place all your components.  Then, add each wires, one by one by going back to the previous challenges.

When you are done, email us pictures of your project or a link to a YouTube video.  We would love to see what you made!

Place your LED and resistors

Place 3 RGB LED on your Arduino shield.

Place a 330 Ohms resistor in front of each pin (except the Cathode - the long lead).

 

Place your control components

Place the components from all other challenges on your new breadboard (the 3 buttons, the potentiometer and the temperature sensor).  Add the resistors in the same way as the previous challenges

The main difference in this challenge is that the power supply and ground connections.  On this new breadboard, these connections are done on the red line (power supply) or the blue line (GND).  Make sure to connect both of them back to the shield.

Your code

/* Welcome to Edition 2, Challenge 2

Title:     Fireworks Grand Finale
Edition:   2
Challenge: 4
Author:    Stephane

Description: In this challenge, use all the skills you learned
and make a grand finale with 3 RGB LEDs at the same time.
*/

// Load the johhny-five library and commands
var five = require('johnny-five');
var board = new five.Board();

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

  // define all 3 RGB LEDs (each color)
  var red1 = new five.Led(9);    // RGB LED 1 color Red
  var blue1 = new five.Led(10);  // RGB LED 1 color Blue
  var green1 = new five.Led(11); // RGB LED 1 color Green
  var red2 = new five.Led(6);    // RGB LED 2 color Red
  var blue2 = new five.Led(7);   // RGB LED 2 color Blue
  var green2 = new five.Led(8);  // RGB LED 2 color Green
  var red3 = new five.Led(3);    // RGB LED 3 color Red
  var blue3 = new five.Led(4);   // RGB LED 3 color Blue
  var green3 = new five.Led(5);  // RGB LED 3 color Green

  // define all three buttons
  var but1 = new five.Button("A1"); // Button 1 on Analog Pin A1
  var but2 = new five.Button("A2"); // Button 2 on Analog Pin A2
  var but3 = new five.Button("A3"); // Button 3 on Analog Pin A3

  // define the sensors
  var pot = new five.Sensor("A4");  // Potentiometer on Analog Pin A4
  var cel = new five.Sensor("A5");  // Temperature sensor on Analog Pin A5

  // When button 1 is pressed
  but1.on('press', function() {
    red3.toggle();
  });

  // When button 2 is pressed
  but2.on('press', function() {
    blue3.toggle();
  });
 
  // When button 3 is pressed
  but3.on('press', function() {
    green3.toggle();
  });

    // When temperature sensor value changes
  cel.on("change", function() {

    console.log('value=' + this.value );

    // adjust the values based on your tests
    if ( this.value > 760 ) {
      red2.blink(this.value);
    } else if ( this.value > 430 ) {
      blue2.blink(this.value);
    } else if ( this.value > 0) {
      green2.blink(this.value);
    }
  });

  // When the potentiometer value changes
  pot.on("change", function() {
    console.log('value=' + this.value );
    // adjust the values based on your tests
    if ( this.value > 460 ) {
      red1.blink(this.value);
    } else if ( this.value > 430 ) {
      blue1.blink(this.value);
    } else if ( this.value > 410) {
      green1.blink(this.value);
    }
  });

});