Hardware Reference
In-Depth Information
else
{
bitClear(_chip1Output, pos - 8);
}
Wire.beginTransmission(_chip1Address);
Wire.write(_chip1Output);
Wire.endTransmission();
}
return true;
}
Because the PCF8574AP can't actually read what it is outputting, when the
user wants to modify a single bit, the function needs to know what the data is
on the bus and then modify it. This is why it was necessary to save the output
as a variable. This is the benei t of using a library, hiding a detail that end users
don't need to know. Users can just see that they can modify a bit with a single
instruction.
Examples
It doesn't matter how clear function names are; libraries are always better with
examples. Example sketches also serve another purposeā€”to test the hardware.
One of the best ways to test if the hardware is correctly set up is to open up an
example and see it run. Even if the shield it drives is basic, users will still use
example sketches as a basis for their own. Put simply: Example sketches need
to clearly demonstrate the functionality of the library.
This library has two examples: one for writing outputs and the other for reading.
Of course, the shield can do both at the same time, so comments need to be put
in place to tell the user that. Also, critically important, the PCF8574AP can read
inputs correctly only if the output is set to high; this needs to be clearly explained
in a comment.
First, for the example to write outputs, you must think about what the user
needs. Of course, he needs to understand the library. He will also need to set
up an example. LCD screen examples are easy to set up; if you are using an
LCD library, you probably already have the LCD screen. This case is different.
Nothing on this particular shield is visible to the user; there are no LEDs, no
LCD screens, nothing that can tell the user what is going on. To see what the
shield can do, a user will have to add his own components. What should you use?
Nothing too fancy. An awesome example would be to use an 8x8 LED matrix,
but not everyone will have that. Don't use specii c hardware in examples; use
tools that are readily available. The cheapest, most readily available, and most
robust component available to makers is the trusty LED; almost everyone has a
 
Search WWH ::




Custom Search