Page 48
Sample Program for Using KIPR Link Digital Output to Light an LED
By default the digital ports for the KIPR Link are configured for input. The KIPR Link Library function
set_digital_output
is used to configure digital port direction; for example,
set_digital_output(
9
,
1
);
configures port 9 for output and
set_digital_output(
9
,
0
);
configures it for input.
For a digital port configured for output, the KIPR Link Library function
set_digital_value
is used to set
the port's output value to either 0 (low) or 1 (high); for example,
set_digital_value(
9
,
1
);
sets the output value for port 9 high
.
If you have 5mm LED on hand, you can use the following program to operate it. An LED will "turn on"
when voltage applied to its anode lead rises above a prescribed level (typically between 1.9 and 3.2V,
depending on color). If too much current is passed through the LED, it will burn out (the typical spec is
20-30mA). For the KIPR Link, digital outputs on the
SEN
rail are sufficiently current limited to operate an
LED without burning it out.
The LED's anode is normally identified by having the longer of the two leads.
Additionally, the flange at the base of the LED is normally flattened on the cathode side.
Setup
Insert the LED's anode lead into port 9's
SEN
line and the cathode lead into the a slot on the
GND
rail.
Code
anode (+)
c
cathode (−)
/* This is a program to blink an LED plugged into digital port 9 */
int
main()
{
printf(
"LED in port 9\n"
);
printf(
"Press side button to quit\n"
);
set_digital_
output
(
9
,
1
);
while
(side_button() == 0) {
set_digital_
value
(
9
,
1
);
msleep(
500
);
set_digital_
value
(
9
,
0
);
msleep(
500
);
}
set_digital_
output
(
9
,
0
);
printf(
"\ndone\n"
);
}