Hardware Reference
In-Depth Information
time = micros();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
}
This function has a minimum number of microseconds that can be correctly
evaluated. On Arduinos with a clock speed of 16 MHz, the resolution is 4 micro-
seconds. On 8 MHz models, the resolution is 8 microseconds.
Mathematical Functions
The Arduino is a capable calculator, and the Arduino language has a large
amount of mathematical functions to help you calculate. They can be used
for simple calculations, to quickly analyze the voltage of one pin compared to
another, or more advanced functions, to help robots move around and calculate
the best path available.
min()
min() returns the smaller of two numbers.
result = min(x, y)
The two values can be of any numerical data type, returning the same data
type as the parameter. This is used both as a way of knowing the smaller of
two values and also to constrain data range; by using min() , you can make sure
that an input value never goes over a certain value.
int sensorData = 100;
min(sensorData, 255); // Returns 100 (sensorData is smaller)
min(sensorData, 100); // Returns 100
min(sensorData, 64); //Returns 64
max()
max() is similar to min() , except it returns the higher of two values.
result = max(x, y)
max() can take any numerical data type and can be used to obtain a minimum
value for sensor data.
int sensorData = 100;
max(sensorData, 255); // Returns 255
max(sensorData, 100); // Returns 100 (both values are the same)
 
Search WWH ::




Custom Search