digital_read() – Digitalio Input Function
Description: Reads the state of the indicated input
Syntax: int digital_read(uint8_t pin)
Parameters: Pin: The number of the pin to read.
Returns: HIGH, LOW, or ERROR.
// wait until the monkey pushes the
// button then give him some candy
while(digital_read( 8) == HIGH); // wait forever for the
digital_write( 9,HIGH); // open the candy door
digital_write() – Digitalio Output Function
Description: Sets the state of the indicated output
Syntax: void digital_write(uint8_t pin, uint8_t value)
Pin: Pin to set either HIGH or LOW.
Value: HIGH or LOW.
if(digital_read( 8) == LOW) // did somebody trip the
digital_write( 7) = HIGH; // if so, turn on the lights
■ FIGURE 4. Schematic for DIP switch to
Butterfly pins 0 through 15.
The Source Code
This code is written for both the Butterfly and the
The tester is very simple
and merely reads the DIP
switch and shows the state on
the LEDs. Once you build the
hardware for this and get it all
working, be sure and save it
for next month where we will
do some more complex things
using the same setup.
■ FIGURE 5. Schematic for LEDs to Butterfly pins 8 through 15.
Using the Digitalio
Since this about input and
output, let’s dig out that eight-bit DIP switch and use it to set
the states on eight LEDs. In
Figure 2, you see the Butterfly
pins for ports B and D shown