Page 18
Digital sensors typically only have two wires and are wired such that when the sensor is triggered the
SEN
and
GND
lines complete a circuit. Analog sensors can have two or three wires. For an analog
sensor the resistance between the
SEN
and
GND
lines will vary. The third wire is connected to
V
CC
to
power the sensor if the sensor requires a power source in order to operate (e.g., a reflectance sensor
has an IR emitter which has to be powered to work).
The voltage on the KIPR Link from
V
CC
to
GND
is set to +5V for both digital and analog ports. The voltage
range between
SEN
and
GND
is also +5V
for both digital and analog ports. The +5V setting is established
by internal jumper settings, and opening the case to change them will void your warranty. It is
suggested that you first contact KIPR Technical Support if you think this is something your application
requires. Instructions for accessing the jumpers are in the appendix as are specifications for creating
your own sensors.
KIPR Link Library Functions for Sensors
The two most basic library functions for using sensors with the KIPR Link are the
analog10
and
digital
functions.
analog10(<port#>)
Analog sensors produce a varying voltage value as resistance between
SEN
and
GND
varies.
analog10
returns the analog value of the port (a value in the range 0-1023). Analog ports are
numbered 0-7. Light sensors and range sensors are examples of sensors you would use in analog
ports. The following example is for a light sensor plugged into analog port 3:
printf(
"Light sensor reading is %d\n"
, analog10(
3
));
digital(<port#>)
Digital sensors operate like a switch, effectively producing a resistance value between
SEN
and
GND
of either none (switch closed) or
∞
(switch open). The
digital
function returns 0 if the
switch is open (
∞
resistance) and 1 if the switch is closed (no resistance). The digital ports on
the KIPR Link are numbered 8-15. Touch sensors are typical digital sensors, commonly used for
bumpers or limit switches. The following example is for a button (touch) sensor plugged into
port 8:
if
(digital(
8
)==
1
)
printf(
"button is being pressed\n"
);
else
printf(
"button is not being pressed\n"
);
The C language prototypes for these two functions are:
int
analog10(
int
port_no);
int
digital(
int
port_no);