116
116
Making a Function
●
To make this useful for other
programs, this program needs to
be turned into a function.
●
A function is a subroutine or
chunk of code that can be called
by a name instead of the code
being inserted where ever it is
needed. This function will return a
result.
●
The return command specifies
which variable is sent back to the
calling code.
long ultrasonic()
{
digitalWrite(5,LOW);
delayMicroseconds(2);
digitalWrite(5,HIGH);
delayMicroseconds(10);
digitalWrite(5,LOW);
long distance = pulseIn(3,HIGH);
if(distance == 0) return(1000);
distance = distance/58;
return(distance);
}
The function
pulseIn()
returns
the number of microseconds.
The result is then divided by 58 to
calculate the distance in
centimeters.
Summary of Contents for StenBOT Rover Kit
Page 1: ...1 StenBOT Rover Kit Stensat Group LLC Copyright 2013 ...
Page 4: ...4 Overview ...
Page 22: ...22 22 Assembly ...
Page 58: ...58 58 Processor Board and Arduino Software ...
Page 118: ...118 118 Completing The Robot Motion ...
Page 138: ...138 138 Digital Signal Connections ...
Page 166: ...166 166 Remote Control ...