Libraries \ Constrain

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name

Constrained

Examples
#include <Constrain.h>

Constrained<float> constrainedFloat( 0.2, 0.0, 1.0 );
Constrained<byte> constrainedByte( 2, 0, 10 );

void setup()
{
  Serial.begin(9800);
  Serial.println("We have two constrained variables."); 
  Serial.println("The first is a float, constrained to be within [0,1].");
  Serial.println("The other is a byte that is constrained to be within [0,10]");
  Serial.println("Setting the variables to 0");
  //set/reset the variable
  constrainedByte = 0;
  constrainedFloat = 0;
  Serial.println("Trying to make the variables exceed the constraint");
  for (byte i=0; i<12; i++)
  {
    Serial.print((float)constrainedFloat); //access value
    Serial.print(" ");
    Serial.println((byte)constrainedByte,DEC);
    constrainedFloat += 0.1;
    constrainedByte++;
  }
  Serial.println("Trying to make the variables go below the constraint");
  for (byte i=0; i<12; i++)
  {
    Serial.print(constrainedFloat.value);
    Serial.print(" ");
    Serial.println(constrainedByte.value,DEC);
    constrainedFloat -= 0.1;
    constrainedByte--;
  }
}

void loop() {
}
Description Initializes the Constrained value.
Syntax
Constrained < typename > ( val , min , max )
Methods
value()
minimum()
maximum()
Parameters
typename Any valid datatype: int, float, byte.
val The initial value of this Constrained value
min The minimum value of this Constrained value
max The maximum value of this Constrained value
Returns None
Usage Application
Updated on July 07, 2011 11:09:46pm PDT

Creative Commons License