Language: EN

libreria-de-arduino-easing

Arduino Easing Library

The Arduino Easing library implements functions to smoothly transition between changes in a variable (e.g., to smoothly change the speed of a motor).

To use it, simply create an instance of the ‘Easing’ object and use the ’=’ operator to change the SetPoint. Then use the ‘GetValue()’ function to obtain the smoothed value.

The smoothing interval can be changed either during the instance creation, in the constructor, or through the ‘SetMillisInterval()’ or ‘SetMicrosInterval()’ functions. Additionally, the ‘Init()’ function can be used to immediately change the Setpoint and the variable.

Available Usage Modes

The available modes are:

LINEAR
EASE_IN_QUAD
EASE_OUT_QUAD
EASE_IN_OUT_QUAD
EASE_IN_CUBIC
EASE_OUT_CUBIC
EASE_IN_OUT_CUBIC
EASE_IN_QUART
EASE_OUT_QUART
EASE_IN_OUT_QUART
EASE_IN_QUINT
EASE_OUT_QUINT
EASE_IN_OUT_QUINT

Function Order

There are five available function orders (LINEAR, QUAD, CUBIC, QUART, QUINT). A higher order implies a smoother transition zone, but a steeper slope in the middle parts of the transition.

arduino-easing-modes

Easing IN, OUT, IN-OUT

There are three transition modes available (IN, OUT, IN-OUT).

arduino-easing-in-out

Examples

The Arduino Easing library includes the following examples to illustrate its use.

  • Example: Example showing the use of Easing
#include "EasingLib.h"

int values[8] = { 0, 1000, 4000, 2000, 1000, 3000, 5000, 1000 };

// Default constructor (EASE_IN_OUT_CUBIC, 1000ms)
Easing easing();

// Full constructor
// Easing easing(ease_mode::LINEAR, 500);

void setup() 
{
  while (!Serial){};

  Serial.begin(115200);

  for(auto i = 0; i < 240; i++)
  {
    auto index = i / 30;
    float newValue = values[index];
    
    Serial.print(newValue);
    Serial.print(',');
    Serial.println(easing.SetSetpoint(newValue));

    delay(50);
  }
}

void loop()
{ 
}

Installation

  • Download the latest version from GitHub
  • Unzip the file
  • Copy it to your libraries folder (usually My Documents\Arduino\libraries)
  • Restart the Arduino IDE

github-full