Skip to content

berrak/LedTask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Display

GitHub license Installation instructions GitHub version GitHub Release Date GitHub stars GitHub issues Documentation Badge Hit Counter

Arduino library LedTask

The Arduino library LedTask shows the power of non-preemptive multitasking. LedTask shows an elementary example with four LEDs, and these run close to independently of each other.

Why try this library?

  • try it and modify the source code for exploration.
  • use it as a starter and move on to a more sophisticated variant like Makuna Task
  • get inspired and explore what more Arduino has to offer. Search in Library Manager - for multitask.

The purpose of this library is to be a practical eye-opener and encourage writing Arduino code differently without inefficient delay() calls.

The library methods

Instantiation of the object and assigning the pin number:

LedTask Led1 = LedTask(7);   // Control a LED
LedTask Led2 = LedTask(8);   // Control another LED
LedTask Fan = LedTask(12);   // Control a DC motor with PWM

Setup variants:

Led1.begin(100, 400); // LED time: on_ms,off_ms
Fan.begin(5.0);       // Low frequency (5 Hz) PWM output on the 'Fan' pin

Loop methods usage:

Led1.updateBlinkLed();   // Blink led with set on/off timing
Fan.updatePwmTask(40);   // Use 40% duty-cycle, with set frequency

An attached LED can use PWM to dim the intensity. See below for the complete library documentation. There is one last method, which is blocking (uses delay() calls, and thus should not be used in the Arduino loop():

// This produces a burst of three blinks, with 100ms on time and 150 ms off time.
Led2.pulseLedBlk(3, 100, 150);	

Run the first example

Connect either four individual LEDs with a limiting 1 kOhm resistor to VCC, or get yourself the TinyLedSwitch - A Universal Breakout Board. Please see below for how to purchase it.

Platform Digital Pin# Led# Cathode
Arduino Uno 12 Led1
Arduino Uno 13 Led2
Arduino Uno 8 Led3
Arduino Uno 7 Led4

Find four free digital pins for any other microcontrollers and adjust them in the Arduino example sketch.

In the Arduino IDE, scroll down the long list below File->Examples and find LedTask. Upload the code, and the four LEDs flash seemingly independently of each other.

Each instance of a LedTask requires just three lines of code:

  • one to declare the instance
  • one to setup timing in the setup
  • and one call to update the loop
LedTask LedOne = LedTask(12);
void setup() {
//                 on_ms,off_ms
	LedOne.begin(100, 400);
}
void loop() {
	LedOne.updateBlinkLed();
}

Another exciting example worth looking at is the capability to separate a short key press from a long key press.

Display

Documentation (GitHub Pages - Doxygen)

Library documentation.

How to Install

Click on the green Library Manager badge above for instructions, or use the alternative manual installation procedure.

  1. Navigate to the Releases page.
  2. Download the latest released ZIP archive in ~/Arduino/libraries.
  3. Unzip the archive.
  4. Rename the new directory. Remove version-code, or master in the name like this for LedTask.
  5. Restart Arduino IDE.
  6. In Arduino IDE scroll down the long list below Sketch->Include Library and find LedTask. Do you like the tiny breadboard-friendly 'LEDs, and switches break-out board'?

You can purchase all the latest designed boards on Tindie.

Tindie

We appreciate your support.

Library user interface changes

The library API changed in release v0.2.0.

Starting point and credits

For a good starting point for understanding non-preemptive multitasking, thank Bill Earl and his write-up on the subject in his article.

About

The Arduino library LedTask shows the power of non-preemptive multitasking. LedTask shows an elementary example with four LEDs, and these run close to independent of each other.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages