Edition 2 - Challenge 1 - The Color Selector

Challenge:  Welcome to your 1st challenge!  Help Leddy and Reggie make a color selector for their fireworks.  Using a set of 3 buttons, control each color of the RGB LED independently.  Use the first button for red, the second button for blue and the third button for green.  When each button is pressed, turn the associated color on.  When the same button is pressed again, turn that color off.  On and Off like this is called "toggle" and you can use the .toggle method of your LED object in the code.

Place your components

Insert the three buttons on your breadboard, across the middle.  Add a 100K resistor (brown-black-yellow-gold) for each button.  Each resistor will have one of the lead connected to ground (GND).

Place your RGB LED somewhere on the breadboard, away from the buttons.  Each color will need a 330 Ohms resistors (orange-orange-brown-gold).  Leave the common cathode free

Place your wires

Next step, add all the wires needed for your components.  You can choose your own colors, but try to keep them the same as the picture here to make it easier to debug your circuit in case of problems.

  • Analog Inputs:  Connect each button/resistor to an analog input pin (A1, A2 and A3 as shown on the picture)
  • Digital Outputs:  Connect each resistor from the LED to a digital output pin (D9, D10 and D11).
  • Power to the buttons:  Connect each button to the power supply (+5V)

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 1

Title:     The Color Selector
Edition:   2
Challenge: 1
Author:    Reggie

Description: Help Leddy and Reggie make a color selector
for their fireworks using three tactile switches to control
each color.

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

// When the board is ready, run this function
board.on('ready', function() {

  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

  var push_red = new five.Button("A3");   // button on Analog Pin A3
  var push_green = new five.Button("A2"); // button on Analog Pin A2
  var push_blue = new five.Button("A1");  // button on Analog Pin A1

  // when button Red is pushed, toggle the red LED
  push_red.on('press', function() {

  // when button Green is pushed, toggle the green LED
  push_green.on('press', function() {

  // when button Blue is pushed, toggle the blue LED
  push_blue.on('press', function() {


Next Experiment

Replace the "toggle()" call with a call to "pulse(1000)" and see what happens.