Learn Arduino: Lecture 10
Learn Arduino: Lecture 10
delay(ms)
Parameters :
ms : the number of milliseconds to pause
No other reading of sensors, mathematical calculations or pin manipulation
can go on during the delay() function. So knowledgeable programmers try to
avoid this delay() function.
delayMicroseconds()
Pauses the program for the amount of time in microseconds.
Syntax
delayMicroseconds(ms)
Parameters :
ms : the number of microseconds to pause
For delays longer than a few thousand microseconds, delay() function should
be used.
It will not work precisely for smaller delay times.
millis()
Returns the number of milliseconds since the Arduino board began running
the current program.
Syntax
Time = millis()
Time = micros()
min(x,y)
Parameters
x: the first number, any data type
y: the second number, any data type
Returns
The smaller of the two numbers.
max()
Calculates the maximum of two numbers.
Syntax
max(x,y)
Parameters
x: the first number, any data type
y: the second number, any data type
Returns
The larger of the two numbers.
map()
Re-maps a number from one range to another.
Syntax
random(max)
random(min, max)
Parameters
min - lower bound of the random value, inclusive (optional)
max - upper bound of the random value, exclusive
Returns
A random number between min and max-1 (long).
randomSeed()
Initializes the pseudo-random number generator, causing it to start at an
arbitrary point in its random sequence.
Syntax
randomSeed(seed)
Parameters
seed - number to initialize the pseudo-random sequence (unsigned long).
Returns nothing.
It is better to use randomSeed() to initialize the random number generator
with a fairly random input, such as analogRead() on an unconnected pin.
Trigonometric Functions
Calculates the sine, cosine or tangent value of an angle.
Syntax
sin(rad)
cos(rad)
tan(rad)
Parameters
rad: The angle in Radians (float).
Returns
The corresponding sine, cosine or tangent of the angle (double).
abs()
Calculates the absolute value of a number.
Syntax
abs(number)
Parameters
number : an integer or float
Returns
x: if x is greater than or equal to 0.
-x: if x is less than 0.
pow()
Calculates the value of a number raised to a power.
Syntax
pow(base,exponent)
Parameters
base: the number (float)
exponent: the power to which the base is raised (float)
Returns
The result of the exponentiation(double).
sqrt()
Calculates the square root of a number.
Syntax
sqrt(number)
Parameters
number : all data types
Returns
The number’s square root(double).
constrain()
Constrains a number to be within a range.
Syntax
constrain(x,a,b)
Parameters
x: the number to constrain, all data types
a: the lower end of the range, all data types
b: the upper end of the range, all data types
Returns
x: if x is between a and b
a: if x is less than a
b: if x is greater than b
Bits
bitRead : Reads a bit of a number.
bitWrite : Writes a bit of a numeric variable.
Syntax
bitRead(x,n)
bitWrite(x,n,b)
Parameters
x: the numeric variable to which to write
n: bit of the number, starting at 0 for the least-significant (rightmost) bit
b: the value to write to the bit (0 or 1)
Byte
lowByte : Extracts the low-order (rightmost) byte of a variable.
highByte : Extracts the high-order (leftmost) byte of a variable.
Syntax
lowByte(value)
highByte(value)
Parameters
value : a vaule of any type
Returns
byte
Now you have the power to
write programs…