LEDs - Controlling an array of LEDs

Demonstrates controlling multiple LEDs at once through the use of an LED array and an analog Potentiometer.

Breadboard for "LEDs - Controlling an array of LEDs"

docs/breadboard/led-array-controller.png

Fritzing diagram: docs/breadboard/led-array-controller.fzz

 

Run this example from the command line with:

node eg/led-array-controller.js
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var leds = new five.Leds([2, 3, 4, 5, 6]);
  var pot = new five.Sensor("A0");

  pot.scale([-1, 4]).on("change", function() {
    var lastIndex = Math.round(this.value);

    if (lastIndex === -1) {
      leds.off();
    } else {
      leds.each(function(led, index) {
        if (index <= lastIndex) {
          led.on();
        } else {
          led.off();
        }
      });
    }
  });
});

 

License

Copyright (c) 2012, 2013, 2014 Rick Waldron waldron.rick@gmail.com Licensed under the MIT license. Copyright (c) 2016 The Johnny-Five Contributors Licensed under the MIT license.