Rate Randomizer - AlbertGBarber/PixelSpork GitHub Wiki

See the Documentation Guide for help understanding each page section.

Description:

A utility class whose output is a random offset from a base number (uint16_t). For example, with a base number of 80 and and offset range of +/- 20, the output could be any number between 60 and 100. This is useful for randomly varying the update rate of effects, but could be used for other purposes. Note that this is a full class, so the utility produces a new output value at regular intervals as it is updated at its update rate.

The output value is stored as outputRate.

You can use the output rate in your effects like:

yourEffect.rate = &yourRateRandomizer.outputRate;
//The line above binds an effect's "rate" setting to the "outputRate" of the rate control utility
//Because the effect's update "rate" is a pointer, but the utility's outputRate is not, 
//we use "&" to bind it by address.
//Note that this means that both settings point to same place in memory
//If you want to change the effect's rate to something else, you'll need to bind it to a new variable.

Note that you cannot use the outputRate in an effect's constructor, you must bind it after the effect has been created.

Finally, note that the base rate (baseRate) is a pointer, like the typical effect rate setting. By default it is bound to the local utility setting baseRateOrig, which is set to whatever BaseRate value you use in the constructor. See common vars rate entry for more info.

Example Calls:

RateRandomizerPS rateRand(80, -10, 10, 300);
/*  Produces a  random rate using a base of 80, 
    and upper and lower bounds of +/- 10.
    So the output will be vary from 70 to 90
    The output rate will change every 300ms. */

Constructor Definitions:

RateRandomizerPS(uint16_t BaseRate, int32_t RateRangeMin, int32_t RateRangeMax, uint16_t Rate);

Constructor Inputs:

  • uint16_t baseRate -- The base rate that the random rate is added/subtracted from. Like the utility's update rate, it is a pointer. By default it's bound to the utility's local variable, baseRateOrig. See common vars rate entry for more.

  • int32_t rateRangeMin (range +/- 65535) -- The lowest possible value that can be added to the baseRate.

  • int32_t rateRangeMax (range +/- 65535) -- The highest possible value that can be added to the baseRate.

  • uint16_t* rate -- Update rate (ms). Is a pointer, allowing you to bind it to an external variable. By default it's bound the effect's local variable, rateOrig. See common vars rate entry for more.

Outputs:

  • uint16_t outputRate -- The output rate of the utility (see intro).

Other Settings:

  • bool active (default true) -- If false, the utility/effect will be disabled (updates() will be ignored). See common vars active entry for more details.

Class Functions:

  • void resetToBaseRate(); 
    

    Resets the outputRate to the baseRate. Also sets active to false, turning off the utility.

  • void update();
    

    Updates the effect.