Arduino - Output Library

When using Arduino's output pin to control LED, relay..., beginners usually run into the following troubles:

The ezOutput (easy output) library is designed to solve all of the above problems and make it easy to use for not only beginners but also experienced users. It is created by ArduioGetStarted.com.

The library can be used for LED, relay, or an..​.

Library Features

  • Support HIGH, LOW, PULSE and TOGGLE
  • Support get state of output pin
  • Supports blink without delay
  • Supports blink in a period
  • Easy to use with multiple output pins
  • Support time offset in blinks multiple output pins
  • All functions are non-blocking

※ NOTE THAT:

If this library is useful for your work, you can say thanks to us by buying us a coffee: PayPal.Me/arduinogetstarted

How To Install Library

  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search “ezOutput”, then find the output library by ArduinoGetStarted
  • Click Install button to install ezOutput library.
Arduino output library

Or you can download it on Github

Functions

  • ezOutput()
  • high()
  • low()
  • toggle()
  • pulse()
  • blink()
  • getState()
  • loop()

References

ezOutput()

Description

This function creates a new instance of the ezOutput class that represents a particular output pin of your Arduino board.

Syntax

ezOutput(pin)

Parameters

pin: int - Arduino's pin.

Return

A new instance of the ezOutput class.

Example

ezOutput led(7);

high()

Description

This function sets output pin to HIGH.

Syntax

led.high();

Parameters

None

Return

None

Example

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9 void setup() { led.high(); } void loop() { }

low()

Description

This function sets output pin to LOW.

Syntax

led.low();

Parameters

None

Return

None

Example

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9 void setup() { led.low(); } void loop() { }

toggle()

Description

This function changes the state of output pin. If the current state is HIGH, this function changes the state to LOW, and vice versa.

Syntax

led.toggle()
led.toggle(delayTime)

Parameters

  • delayTime: unsigned long (in millisecond) - (optional) the time output pin is delayed before toggling. When we use this parameter, We have to call loop() function as fast as possible.

Return

None

Example

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9 void setup() { } void loop() { led.toggle(); delay(1000); }

pulse()

Description

This function generates a square pulse.

  • If the current state is LOW, this function generates a HIGH pulse.
  • If the current state is HIGH, this function generates a LOW pulse.

We have to call loop() function as fast as possible.

Syntax

led.pulse(pulseTime)
led.pulse(pulseTime, delayTime)

Parameters

  • pulseTime: unsigned long (in millisecond) - the duration of pulse.
  • delayTime: unsigned long (in millisecond) - (optional) the time output pin is delayed before a pulse starts.

Return

None

Example - HIGH pulse

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9 void setup() { led.low(); delay(5000); // just delay to see clear pulse led.pulse(1000, 250); // 250 milliseconds delay, 1000 milliseconds HIGH pulse, } void loop() { led.loop(); }

Example - LOW pulse

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9 void setup() { led.high(); delay(5000); // just delay to see clear pulse led.pulse(1000, 250); // 250 milliseconds delay, 1000 milliseconds LOW pulse, } void loop() { led.loop(); }

blink()

Description

This function blinks (toggles) output pin continuously with specified LOW time and HIGH time. To keep blinking, we have to call loop() function as fast as possible. If the blink time is not specified, the blinking will be disabled only if we call low(), high() or toggle() functions.

Syntax

led.blink(lowTime, highTime)
led.blink(lowTime, highTime, delayTime)
led.blink(lowTime, highTime, delayTime, blinkTimes)

Parameters

  • lowTime: unsigned long (in millisecond) - the time output pin is LOW in milliseconds.
  • highTime: unsigned long (in millisecond) - the time output pin is HIGH in milliseconds.
  • delayTime: unsigned long (in millisecond) - (optional) the time output pin is delayed before blinking. This is used when we want to blink multiple output pin with delay among the pins. If not set, the blinking is started immediately.
  • blinkTimes: long - (optional) The number of times output toggles (changes between LOW to HIGH and HIGH to LOW). If not set, output blinks forever

Return

None

Example 1

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9; void setup() { led.blink(500, 250); // 500 milliseconds OFF, 250 milliseconds ON } void loop() { led.loop(); // MUST call the led.loop() function in loop() }

Example 2

#include <ezOutput.h> // ezOutput library ezOutput led1(7); // create ezOutput object that attach to pin 7; ezOutput led2(8); // create ezOutput object that attach to pin 8; ezOutput led3(9); // create ezOutput object that attach to pin 9; void setup() { led1.blink(500, 250); // 500 milliseconds OFF, 250 milliseconds ON, start immediately, blink forever led2.blink(250, 250, 1000); // 250 milliseconds OFF, 250 milliseconds ON, start after 1000 milliseconds, blink forever led3.blink(0, 100, 0, 2); // 0 milliseconds OFF, 100 milliseconds ON, start immediately, // since toggle times is 2. it changes: OFF -> ON, keeps ON 100ms, // then ON -> OFF, and then stops. } void loop() { led1.loop(); // MUST call the led1.loop() function in loop() led2.loop(); // MUST call the led2.loop() function in loop() led3.loop(); // MUST call the led3.loop() function in loop() }

getState()

This function returns the current state of output pin.

Description

Syntax

button.getStateRaw()

Parameters

None

Return

The current state of output pin.

Example

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9; void setup() { Serial.begin(9600); } void loop() { led.toggle(); Serial.println(led.getState()); delay(1000); }

loop()

loop()

Description

This function blinks output. It is used in combination with blink() function.

Syntax

button.loop();

Parameters

None

Return

None

Example

#include <ezOutput.h> // ezOutput library ezOutput led(9); // create ezOutput object that attach to pin 9; void setup() { led.blink(500, 250); // 500 milliseconds ON, 250 milliseconds OFF } void loop() { led.loop(); // MUST call the led.loop() function in loop() }

The Best Arduino Starter Kit

See Also

※ OUR MESSAGES