Difference between revisions of "Mixly Block Category - Math"
(→Arithmetic Operations) |
(→Number Function) |
||
(15 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
=Arithmetic Operations= | =Arithmetic Operations= | ||
− | Performs the arithmetic operations | + | Performs the arithmetic operations on the left input with the right input. Then returns that value. Variables can be used to inputs. |
* +, -, x, ÷ : add, subtract, multiply, divide. Read more here: https://www.arduino.cc/en/Reference/Arithmetic | * +, -, x, ÷ : add, subtract, multiply, divide. Read more here: https://www.arduino.cc/en/Reference/Arithmetic | ||
* % : modulo. Read more here: https://www.arduino.cc/en/Reference/modulo | * % : modulo. Read more here: https://www.arduino.cc/en/Reference/modulo | ||
Line 9: | Line 9: | ||
=Trigonometry Function= | =Trigonometry Function= | ||
+ | * sin- Takes the sin of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sin | ||
+ | * cos - Takes the cos of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Cos | ||
+ | * tan - Takes the tan of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Tan | ||
+ | * asin, acos, atan. Read more here: https://www.arduino.cc/en/Math/H | ||
+ | |||
=Number Function= | =Number Function= | ||
− | *toInt | + | *toInt - Converts the input into an Integer type (https://www.arduino.cc/en/Reference/Int) and returns it. Read more here: https://www.arduino.cc/en/Reference/IntCast |
− | *abs | + | *abs - Takes the absolute value of the input and returns it. Read more here: https://www.arduino.cc/en/reference/abs |
− | *sq | + | *sq - Takes the square of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sq |
− | *sqrt | + | *sqrt - Takes the square root of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sqrt |
− | *log | + | *log - Takes the natural log of the input and returns it: Read more here: https://www.arduino.cc/en/Reference/MathHeader |
− | =Max= | + | |
+ | =Max / Min= | ||
+ | *max - Takes the max of the two inputs and returns it. Read more here: https://www.arduino.cc/en/Reference/Max | ||
+ | *min - Takes the min of the two inputs and returns it. Read more here: https://www.arduino.cc/en/Reference/Min | ||
+ | |||
=Random Integer= | =Random Integer= | ||
+ | Returns a random integer between the two input values. | ||
+ | *min (left input) - lower bound of the random value, inclusive (optional) | ||
+ | *max (right input) - upper bound of the random value, exclusive | ||
+ | |||
+ | |||
+ | Example: random('''5''', '''77''') will return a value between '''5''' and '''76'''. | ||
+ | |||
+ | |||
+ | Read more here: https://www.arduino.cc/en/Reference/Random | ||
+ | |||
=Constrain= | =Constrain= | ||
+ | Constrains the '''Input''' to the '''Low''' and '''High''' and returns it. | ||
+ | *Input - Variable or value that will be constrained. | ||
+ | *Low - Lower value that '''Input''' will be constrained to. | ||
+ | *High - Upper value that '''Input''' will be constrained to. | ||
+ | |||
+ | |||
+ | Example 1: Input is '''10''', Low is 5, and High is 15. Constrain returns '''10'''. | ||
+ | |||
+ | Example 2: Input is '''100''', Low is 5, and High is 15. Constrain returns '''15'''. | ||
+ | |||
+ | Example 3: Input is '''2''', Low is 5, and High is 15. Constrain returns '''2'''. | ||
+ | |||
+ | |||
+ | Read more here: https://www.arduino.cc/en/Reference/Constrain | ||
+ | |||
=Map= | =Map= | ||
+ | Re-maps the '''Input''' from one range ['''fromLow''' , '''fromHigh'''] to another range ['''toLow''' , '''toHigh''']. Then returns that value. | ||
+ | |||
+ | That is, a value of '''fromLow''' would get mapped to '''toLow''', a value of '''fromHigh''' to '''toHigh''', values in-between to values in-between, etc. | ||
+ | |||
+ | *Input - Input that will be re-mapped from '''from range''' to '''to range''' . | ||
+ | *From Range | ||
+ | ** fromLow - Low value of the '''from range''' | ||
+ | ** fromHigh - High value of the '''from range''' | ||
+ | *To Range | ||
+ | ** toLow - Low value of the '''to range''' | ||
+ | ** toHigh - High value of the '''to range''' | ||
+ | |||
+ | |||
+ | The function that is used is: | ||
+ | |||
+ | Mapped_Output = (Input - fromLow) * (toHigh - toLow) / (fromMax - fromMin) + toLow | ||
+ | |||
+ | |||
+ | Read more here: https://www.arduino.cc/en/Reference/Map |
Latest revision as of 00:17, 16 February 2017
Contents
Number Value
Numeric value which can be assigned to a variable or used in function parameters.
Arithmetic Operations
Performs the arithmetic operations on the left input with the right input. Then returns that value. Variables can be used to inputs.
- +, -, x, ÷ : add, subtract, multiply, divide. Read more here: https://www.arduino.cc/en/Reference/Arithmetic
- % : modulo. Read more here: https://www.arduino.cc/en/Reference/modulo
- ^ : power. i.e. 2^3 = 2 * 2 * 2 = 8
Trigonometry Function
- sin- Takes the sin of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sin
- cos - Takes the cos of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Cos
- tan - Takes the tan of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Tan
- asin, acos, atan. Read more here: https://www.arduino.cc/en/Math/H
Number Function
- toInt - Converts the input into an Integer type (https://www.arduino.cc/en/Reference/Int) and returns it. Read more here: https://www.arduino.cc/en/Reference/IntCast
- abs - Takes the absolute value of the input and returns it. Read more here: https://www.arduino.cc/en/reference/abs
- sq - Takes the square of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sq
- sqrt - Takes the square root of the input and returns it. Read more here: https://www.arduino.cc/en/Reference/Sqrt
- log - Takes the natural log of the input and returns it: Read more here: https://www.arduino.cc/en/Reference/MathHeader
Max / Min
- max - Takes the max of the two inputs and returns it. Read more here: https://www.arduino.cc/en/Reference/Max
- min - Takes the min of the two inputs and returns it. Read more here: https://www.arduino.cc/en/Reference/Min
Random Integer
Returns a random integer between the two input values.
- min (left input) - lower bound of the random value, inclusive (optional)
- max (right input) - upper bound of the random value, exclusive
Example: random(5, 77) will return a value between 5 and 76.
Read more here: https://www.arduino.cc/en/Reference/Random
Constrain
Constrains the Input to the Low and High and returns it.
- Input - Variable or value that will be constrained.
- Low - Lower value that Input will be constrained to.
- High - Upper value that Input will be constrained to.
Example 1: Input is 10, Low is 5, and High is 15. Constrain returns 10.
Example 2: Input is 100, Low is 5, and High is 15. Constrain returns 15.
Example 3: Input is 2, Low is 5, and High is 15. Constrain returns 2.
Read more here: https://www.arduino.cc/en/Reference/Constrain
Map
Re-maps the Input from one range [fromLow , fromHigh] to another range [toLow , toHigh]. Then returns that value.
That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
- Input - Input that will be re-mapped from from range to to range .
- From Range
- fromLow - Low value of the from range
- fromHigh - High value of the from range
- To Range
- toLow - Low value of the to range
- toHigh - High value of the to range
The function that is used is:
Mapped_Output = (Input - fromLow) * (toHigh - toLow) / (fromMax - fromMin) + toLow
Read more here: https://www.arduino.cc/en/Reference/Map