http://www.platelayer.com/adresseable-led-lights.aspx

PlateLayer by Svein-Martin Holt

 

Adresseable LED's for lights and animations

To create flexible lights and animation effects, the different types of adresseable LED's are an effective and easy way to use on a layout.
There are different types, from ledstripes of various lenghts and density, to single LED's and PCB's where standard LED's can be connected.
A traditional LED-strip has a number of LED's, single color and RGB, where all LED's have the same color and intensity along the strip.

With adresseable LED-strips, you can control each LED individually along the strip. The adresseable LED's are also available as single chips and in "normal" LED-packs.
In general, you can connect several of this LED's in series, with common powersupply lines(+ and -), and a dataline, a total of 3 wires to control hundreds of LED's in a string.
And they can all be controlled with a microcontroller, like the Arduino og Raspberry Pi. On my own layout I use several Arduinos to control the LED's.

An examle in this blog post: Cityline comes to live with lights

In this image there are 54 adresseable LED's in the buildings, all individually adresseable with color and brightness.


Different types of adresseable LED's

Top right: Single WS2811 chips, connected together with 3 wires, power +/- 5 Volt and Data in(from the previous LED) and Data out(to the next LED)
"Normal" looking LED's, with 4 wires, similiar configuration as the single chip type. 3 different types in the image.

 

IC PCB containing a WS2811 Constant Current RGB LED driver, where you can connect individual standard LED's to each of the 3 output, to drive standard LED's. No resistor is necesarry, it will output 3 Volt, 16.5 mA on each output. One big sheet have 100 PCB's that easy can de separated. Its possible to operate other items, like relays, transistors, etc.

 

Here 6 WS2811 PCB's are mounted inside a building, to power single LED street lights in the neighborhood. Only 7 LED's are installed at the moment. At right you can see a single chip LED for the light in the building.

 

FastLed, Adafruit and MobaLedLib
There are available several Arduino libraries to use with this LED's, like FastLED and Adafruit NeoPixels. An extension using FastLED is MobaLedLib. The MobaLedLib makes it very easy to create different lighting and animation effects, specially for the Model Railroad user. Check also out the MobaLedLib wiki. The library gives you the possibility to run several different animations at the same time without thinking about problems using the delay function or counting millis in your own code.

You must install the FastLED and other libraries you want to use in the Arduino IDE program on your computer. Many programming examples can be found under the different libraries, like for FastLED: Files>Examples>FastLed

 

Example of MobaLedLib animation

This Arduino sketch show how easy it is to use the MobaLedLib for blink and welding.

On my new layout, the Zity Edge Layout, I use this library "everywhere" on the layout, for lighs and animation effects.
The blink in this sketch is used on the roof top of some buldings to create a roof red flashing beacon, the welding effect are used in different factory shops to simulate welding.
Both functions are defined in a single configuration line statement in the code.
Its possible to trig the effect with buttons or variables, but in the example both effect runs continuesly.

The sketch use adresseable WS2811, WS2812 LED-strips, where a single dataline is used to drive the different LED's, in addtion to the power for the LED-strip.

The configuration can be done using an Excel spreadsheet that creates the configuration syntax, but you can also define it directly in the sketch.

Check out the video below and the Arduino code where I use WS2811 LED chips mounted on a strip:

The 3 blinking LEDs on the right side, and the welding LED on the left, all driven by a few lines of code using the MobaLedLib library.

 

The Arduino code/sketch:

First part of the code, description and comments:

// MobaLedLib_ex1_blinker_welding.ino by Svein-Martin Holt, www.platelayer.com  --  www.zityedge.com, april 2021

/*
  This Arduino sketch show how easy it is to use the MobaLedLib for blink and welding.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  On my new layout, the Zity Edge Layout, I use this library "everywhere" on the layout, for lighs and animation effects.
  The blink in this sketch is used on the roof top of some buldings to create a roof red flashing beacon,
  the welding effect are used in different factory shops to simulate welding.
  Both functions are defined in a single configuration line statement in the code.
  Its possible to trig the effect with buttons or variables, but in the example both effect runs continuesly.

  The sketch use adresseable WS2811, WS2812 LED-strips, where a single dataline is used to drive the different LED's,
  in addtion to the power for the LED-strip.

  The configuration can be done using an Excel spreadsheet that creates the configuration syntax,
  but you can also define it directly in the sketch.

  Check out the MobaLedLib on the net for more info: https://github.com/Hardi-St/MobaLedLib
  The MobaLedLb wiki: https://wiki.mobaledlib.de/doku.php
  The FastLED homepage: http://fastled.io/
  The Adafruit Neopixel homepage: https://learn.adafruit.com/adafruit-neopixel-uberguide
*/

Include the libraries you need:

#define FASTLED_INTERNAL // Disable version number message in FastLED library (looks like an error)
#include "FastLED.h"     // The FastLED library must be installed

#include "MobaLedLib.h"  // Use the Moba Led Library

Define some variables, like number of LEDs in the strip, pin to use to control the strip:

#define NUM_LEDS     16  // Number of LEDs with some spare channels (Maximal 256 RGB LEDs could be used with MobaLedLib)
#define LED_DO_PIN   2   // Pin D2 is connected to the LED stripe

Always good to define some parameters as variables:

#define LED_NUM_BLINK 1  // Define LED number in string to blink, here the first LED, 1, physical LED number 2
#define LED_NUM_WELD  6  // Define LED number in string to simulate welding, here LED number 6, physical LED number 7

Define the MobaLedLib Configuration, first define 3 different blinking LED's:


//*******************************************************************
// *** Configuration array which defines the behavior of the LEDs ***
MobaLedLib_Configuration()
{
  // Blinker, 1 sec interval on first LED, 2 sec interval on second LED, 0.5 sec interval on third LED
  //      LED: LED number in the stripe
  //      |                  RGB channel
  //      |                  |        InCh: Input channel. Here the special input 1 is used which is always on
  //      |                  |        |     Blink frequency, 1, 2 and 0.5 second
  //      |   |   |          |        |     |
  Blinker(LED_NUM_BLINK,     C1,      SI_1, 1 Sek)   // C1: first RGB LED, Red Flashing LED
  Blinker(LED_NUM_BLINK + 1, C_GREEN, SI_1, 2 Sek)   // C_GREEN: Green Flashing LED
  Blinker(LED_NUM_BLINK + 2, C3,      SI_1, 0.5 Sek) // C3: Blue Flashing LED

Then define the simulation of welding for the building with the factory shop:

  // Welding
  //          LED: LED number in the stripe
  //          |                       InCh: Input channel. Here the special input 1 is used which is always on
  //          |                       |     The different parameters is configured using the Excel sheet or can be found in the documentation
  //          |                       |     |
  RandWelding(LED_NUM_WELD,           SI_1, 0, 10 Sek, 30 Sek, 6 Sek, 10 Sek)

  EndCfg // End of the configuration
};

Setup the LED type, like WS2811 or WS2812, and the color order of the strip. If the order is wring, red light will be grren, and green light will be red.:

// LED Type and LED strip Color order
#define LED_TYPE WS2811
#define COLOR_ORDER GRB   // The Color order depends on the type of LED-strip, RGB or GRB

Define the LED array and the MobaLedLib instance. Use the build in LED to show the heartbeat, a 1 second blink, the Arduino is running.

CRGB leds[NUM_LEDS];     // Define the array of leds

MobaLedLib_Create(leds); // Define the MobaLedLib instance

LED_Heartbeat_C LED_Heartbeat(LED_BUILTIN); // Use the build in LED as heartbeat

Define the one time setup on the Arduino:

void setup() {
  //----------
  // This function is called once to initialize the program
  //
  FastLED.addLeds<LED_TYPE, LED_DO_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Initialize the FastLED library
}

Define the code that will run in the loop on the Arduino:

void loop() {
  //---------
  // This function contains the main loop which is executed continuously
  //
  MobaLedLib.Update();    // Update the LEDs in the configuration

  FastLED.show();         // Show the LEDs (send the leds[] array to the LED stripe)

  LED_Heartbeat.Update(); // Update the heartbeat LED. This must be called periodically in the loop() function.
}

 

The complete Arduino code/sketch:

Copy Code to ClipBoard


// MobaLedLib_ex1_blinker_welding.ino by Svein-Martin Holt, www.platelayer.com  --  www.zityedge.com, april 2021

/*
  This Arduino sketch show how easy it is to use the MobaLedLib for blink and welding.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  On my new layout, the Zity Edge Layout, I use this library "everywhere" on the layout, for lighs and animation effects.
  The blink in this sketch is used on the roof top of some buldings to create a roof red flashing beacon,
  the welding effect are used in different factory shops to simulate welding.
  Both functions are defined in a single configuration line statement in the code.
  Its possible to trig the effect with buttons or variables, but in the example both effect runs continuesly.

  The sketch use adresseable WS2811, WS2812 LED-strips, where a single dataline is used to drive the different LED's,
  in addtion to the power for the LED-strip.

  The configuration can be done using an Excel spreadsheet that creates the configuration syntax,
  but you can also define it directly in the sketch.

  Check out the MobaLedLib on the net for more info: https://github.com/Hardi-St/MobaLedLib
  The MobaLedLb wiki: https://wiki.mobaledlib.de/doku.php
  The FastLED homepage: http://fastled.io/
  The Adafruit Neopixel homepage: https://learn.adafruit.com/adafruit-neopixel-uberguide
*/

#define FASTLED_INTERNAL // Disable version number message in FastLED library (looks like an error)
#include "FastLED.h"     // The FastLED library must be installed

#include "MobaLedLib.h"  // Use the Moba Led Library

#define NUM_LEDS     16  // Number of LEDs with some spare channels (Maximal 256 RGB LEDs could be used with MobaLedLib)
#define LED_DO_PIN   2   // Pin D2 is connected to the LED stripe

#define LED_NUM_BLINK 1  // Define LED number in string to blink, here the first LED, 1, physical LED number 2
#define LED_NUM_WELD  6  // Define LED number in string to simulate welding, here LED number 6, physical LED number 7

//*******************************************************************
// *** Configuration array which defines the behavior of the LEDs ***
MobaLedLib_Configuration()
{
  // Blinker, 1 sec interval on first LED, 2 sec interval on second LED, 0.5 sec interval on third LED
  //      LED: LED number in the stripe
  //      |                  RGB channel
  //      |                  |        InCh: Input channel. Here the special input 1 is used which is always on
  //      |                  |        |     Blink frequency, 1, 2 and 0.5 second
  //      |   |   |          |        |     |
  Blinker(LED_NUM_BLINK,     C1,      SI_1, 1 Sek)   // C1: first RGB LED, Red Flashing LED
  Blinker(LED_NUM_BLINK + 1, C_GREEN, SI_1, 2 Sek)   // C_GREEN: Green Flashing LED
  Blinker(LED_NUM_BLINK + 2, C3,      SI_1, 0.5 Sek) // C3: Blue Flashing LED

  // Welding
  //          LED: LED number in the stripe
  //          |                       InCh: Input channel. Here the special input 1 is used which is always on
  //          |                       |     The different parameters is configured using the Excel sheet or can be found in the documentation
  //          |                       |     |
  RandWelding(LED_NUM_WELD,           SI_1, 0, 10 Sek, 30 Sek, 6 Sek, 10 Sek)

  EndCfg // End of the configuration
};
//*******************************************************************

// LED Type and LED strip Color order
#define LED_TYPE WS2811
#define COLOR_ORDER GRB   // The Color order depends on the type of LED-strip, RGB or GRB

CRGB leds[NUM_LEDS];     // Define the array of leds

MobaLedLib_Create(leds); // Define the MobaLedLib instance

LED_Heartbeat_C LED_Heartbeat(LED_BUILTIN); // Use the build in LED as heartbeat

//----------
void setup() {
  //----------
  // This function is called once to initialize the program
  //
  FastLED.addLeds<LED_TYPE, LED_DO_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Initialize the FastLED library
}

//---------
void loop() {
  //---------
  // This function contains the main loop which is executed continuously
  //
  MobaLedLib.Update();    // Update the LEDs in the configuration

  FastLED.show();         // Show the LEDs (send the leds[] array to the LED stripe)

  LED_Heartbeat.Update(); // Update the heartbeat LED. This must be called periodically in the loop() function.
}

Libraries and resources