I will be maintaining my libraries here: https://bit.ly/pATDBi I am the lead developer for libraries that ship with the Wiring distribution. As per version 1.0 - Wiring will support Arduino boards. You are welcome to check it out! https://wiring.org.co/download/
Constrain Utility for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
I made a simple struct that has constraints that will persist.
The other method is to call constraint every time you need the variable (to be constrained).
Download here: Attach:Constrain.zip
Put the Constrain folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Constrain".
Once the library is imported, an "#include <Constrain.h>" line will appear at the top of your Sketch.
Constrained<datatype> variableName( initialValue , minimumValue , maximumValue );
Constrained<byte> index( 2 , 0 , 6 ); //start at index 2, do not get an index below 0 or above 6. index += 4; //will result in index being 6 index = 10; //will result in index being 6 index = 0; //will result in index being 0 index--; //will result in index being 0
We have two constrained variables. The first is a float, constrained to be within [0,1]. The other is a byte that is constrained to be within [0,10] Setting the variables to 0 Trying to make the variables exceed the constraint 0.00 0 0.10 1 0.20 2 0.30 3 0.40 4 0.50 5 0.60 6 0.70 7 0.80 8 0.90 9 1.00 10 1.00 10 Trying to make the variables go below the constraint 1.00 10 0.90 9 0.80 8 0.70 7 0.60 6 0.50 5 0.40 4 0.30 3 0.20 2 0.10 1 0.00 0 0.00 0
Is a Constrained variable the same as a regular variable (byte,int etc) ?
No. A Constrained variable is actually a struct, but will behave like a regular variable in most ways.
Part of AlphaBeta Utilities. | |
Last Modified: | July 27, 2011, at 12:06 PM |
By: | AlphaBeta |