TDuino
Convenient functionality for Arduino
Functions
Timeline helpers

Functions

int TL_MapToInt (float progress, int low, int high)
 Map to int.
 
unsigned int TL_MapToUInt (float progress, unsigned int low, unsigned int high)
 Map to unsigned int.
 
long TL_MapToLong (float progress, long low, long high)
 Map to long.
 
unsigned long TL_MapToULong (float progress, unsigned long low, unsigned long high)
 Map to unsigned long.
 
float TL_MapToFloat (float progress, float low, float high)
 Map to float.
 

Detailed Description

These functions will help you to convert the progress value passed to the timeline callback to numeric values of different types. All functions takes these three arguments:

progress The float passed to the callback. min The minimum value it should be mapped to. max The maximum value it should be mapped to.

The formula is pretty simple: roundf((float)(max - min) * progress) + min

The are functions for signed and unsigned int + long and for float:

void TimelineCallback(byte slot, float progress)
{
//Map to int value between 1000 and 2000:
int intValue = TL_MapToInt(progress, 1000, 2000);
//Map to long value between 10000 and 20000:
long longValue = TL_MapToLong(progress, 10000, 20000);
//Map to float value between 1.5 and 6.5:
float floatValue = TL_MapToFloat(progress, 1.5f, 6.5f);
}
TTimeline tline(TimelineCallback, 2);