The Noiasca Tool Kit for LEDs

The Noiasca Tool Kit contains several classes: It all starts with helpers to let LEDs blink, dim, flicker and several other effects in parallel without the usage of any delay. Furthermore the tool kit contains a class to read and debounce a button click very easily. Finally, the tool kit brings two different timers, which can be used to start and stop actions. For example if you want to start a blinking LED on button press and let it blink for 10 seconds, just combine a blink LED, the button and a timer from the Noiasca Tool Kit.

The Noiasca Tool Kit contains several classes for different style of LEDs. Each kind of pattern is explained here. Furthermore you are not limited to use the Arduino pins only, you can use this classes also for your WS2812 Neopixels.

On this page only the LED classes are explained in detail, but you will find a lot of examples for buttons and timer in the library examples.

Blink

This is a simple a class to "blink" a LED. You can define the on and the off interval separately.

A very simple sketch will look like following:

#include <Noiasca_led.h>
BlinkPin blinkLed {13};              // declare one blinking LED and assign pin 13

void setup() {
  blinkLed.begin();                  // you have to call the .begin() method for this LED
  //blinkLed.setInterval(700, 300);  // optional: you can define the ON and OFF times in milliseconds
  blinkLed.on();                     // switch the blinking on
}

void loop() {
  blinkLed.update();                 // call the update function in loop() to refresh the LED
  // put other non blocking code here, to run repeatedly
}

 

The constructor makes one blinking LED available on pin 13.

.begin() : The begin() must be called in setup(). It will to all hardware specific tasks. In the case of the blinking LED it will set the pinMode to Output.

.on() will switch the blink effect on.

.update() will do all the magic behind the scenes. It works similar to "Blink without Delay". The class has it's own time management and will switch the pin on or off if it is needed.

There are several other member functions available for the blink LED

.off() will switch off the effect - the LED will get dark.

.toggle() will either switch the effect on or off. This member function comes very handy when you have a single push button and if you want to switch the blinking on or off with each button press.

.setOnInterval(interval) and .setOffInterval(interval) with these member function you can define the on and off times. Default values are 500ms which give you a consistent blinking. If you want a flashing effect, you can make the off time longer then the on time

  blinkLed.setOnInterval(100);                 // 100ms on
  blinkLed.setOffInterval(1000);               // 1000ms off

Alternating

"Alternating" is the blinking of two LEDs vice versa. Either the first or the second LED is on. The constructor of an alternating LED pair needs two pins:

AlternatingPin alternatingLed {2, 4}; 

Bounce5

"Bounce 5" is a LED pattern, with 5 LEDs: Only one LED is on and all LEDs will give an effect of a running LED between left and right. You can compare the effect with the  KITT/Larson Scanner. The constructor for this effect needs 5 pins:

Bounce5Pin bounce5led {2, 3, 4, 5, 6};

Flicker

This effect simulates a "flickering" light like a fire. The pattern is random and you will get an even better effect if you start flicker with two LEDs for example a red and a yellow LED. The effect should run on a PWM enabled pin:

FlickerPin flickerLed {3}; // UNO PWM pins 3, 5, 6, 9, 10, 11

Fluorescent

"Fluorescent" tend to start a little delayed. There might occure a short flicker effect on start up. And it will take a short time till the fluorescent tube (or lamp) will shine in full 100% intensity. You can simulate this effect with an LED. Use an PWM enabled pin for the best effect.

FluorescentPin fluorescentLed {3}; // UNO PWM pins 3, 5, 6, 9, 10, 11

Heartbeat

A "heartbeat" LED will dim up and down permanently. You can define thresholds for the minimum and maximum dim level.

HeartbeatPin heartbeatLed {3}; // UNO PWM pins 3, 5, 6, 9, 10, 11

.setInterval(10) will effect the speed of the dimming. Default value is 50.
.setMinBrightness(50) this will limit the lower end of the dimmrange. Default value is 0 - meaning the LED will switch off
.setMaxBrightness(240) this will limit the maximum brightness. Default value is 255. Highest value on an Arduino is 255.

Pulse

A "pulse" is an high output for a (short) period of time which will return to low. Pulse turns on a LED for a defined period of time without using the delay() function (monoflop). This means that other code can run at the same time without being interrupted by the LED code. The output acts like a monoflop.

PulsePin pulseLed {13}; // any output pin

You are not limited to LEDs. You can use this also to pulse a relay for a specific time. If your relay (or relay module) is LOW active, you can set the optional second parameter to indicate a LOW active output:

PulsePin pulseLed {13, LOW}; // if the pin should be LOW active, set second parameter

Rhythm

A "rhythm" LED can be set up to "blink" in a specific pattern. The rhythm LED supports 1, 2 and 4 pairs of on/off times. This can be used for police cars, ambulances and similar vehicles. The default sequence is ECE2 (150, 60, 20, 270). But you can set any other sequence also (ECE1, HELLA 3, HELLA 4,...) . Just remember that you have to define the pattern in pairs of on and off times.

RhythmPin rhythmLed {13}; // declare LED and assign pin

Smooth

On PWM pins you can use a smooth dim up / down a LED. When you switch the LED on, the LED will get brighter time by time. If you switch it off, it will slowly dimm down.

SmoothPin smoothLed {3}; // UNO PWM pins 3, 5, 6, 9, 10, 11

you can limit the maximum PWM value with following member function:

smoothLed.setMaxBrightness(240); // you can limit the maximum brightness. Highest value on Arduino is 255. Default 255.

The inverse function to retrieve the current brightness is:

uint16_t currentBrightness = smoothLed.getCurrentBrightness();

Trafficlight

A traffic light consist of up to 3 LEDs (red, yellow, green) and can have several faces to be shown

states of a traffic light
0 OFF           // no LED is on
1 RED
2 REDYELLOW     // the RED and the Yellow are on
3 GREEN 
4 YELLOW 
5 YELLOWBLINK   // the traffic light is blinking yellow
6 GREENBLINK    // like used in Austria or Ukraine

Turn signal

The turn signals for a car consists of 2 side markers (for left and right) and an optional hazard warning light in the dashboard.

TurnsignalPin turnsignalPin{2, 3, 4}; // GPIO left, GPIO right, GPIO hazard warning light (optional)

You can switch the turn signal to LEFT, RIGHT and HAZARD. In case of HAZARD, the left and the right LED are blinking in sync. Additionally, the hazard LED for the dashboard indicates the status.

Neopixel WS2812

If you are running out of pins for your LEDs, you could use a strip with Neopixel / WS2812/ APA106 and add a lot of single effects. You can even mix discrete LEDs (connected to an Arduino PIN) and Neopixels in one sketch and run the same effect on different LED hardware. Obviously Neopixel can also be used with different colors.

Links

(*) Disclosure: Some of the links above are affiliate links, meaning, at no additional cost to you I will earn a (little) comission if you click through and make a purchase. I only recommend products I own myself and I'm convinced they are useful for other makers.

History

First upload: 2022-02-02 | Version: 2022-04-11