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"

led-array-controller.png

Fritzing diagram: led-array-controller.fzz

 

Run this example from the command line with:

node eg/led-array-controller.js
const {Board, Leds, Sensor} = require("johnny-five");
const board = new Board();

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

  pot.on("change", () => {
    const lastIndex = Math.round(pot.scaleTo([-1, 4]));

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

 

Component Classes in this example:

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub